log tracebacks in debug mode when unable to detect language

This commit is contained in:
Alan Hamlett 2017-03-04 10:34:06 -08:00
parent 6379953b24
commit 723dd42fa9

View file

@ -117,13 +117,13 @@ def guess_lexer_using_filename(file_name, text):
try: try:
lexer = custom_pygments_guess_lexer_for_filename(file_name, text) lexer = custom_pygments_guess_lexer_for_filename(file_name, text)
except: except:
pass log.traceback(logging.DEBUG)
if lexer is not None: if lexer is not None:
try: try:
accuracy = lexer.analyse_text(text) accuracy = lexer.analyse_text(text)
except: except:
pass log.traceback(logging.DEBUG)
return lexer, accuracy return lexer, accuracy
@ -140,19 +140,19 @@ def guess_lexer_using_modeline(text):
try: try:
file_type = get_filetype_from_buffer(text) file_type = get_filetype_from_buffer(text)
except: # pragma: nocover except: # pragma: nocover
pass log.traceback(logging.DEBUG)
if file_type is not None: if file_type is not None:
try: try:
lexer = get_lexer_by_name(file_type) lexer = get_lexer_by_name(file_type)
except ClassNotFound: except ClassNotFound:
pass log.traceback(logging.DEBUG)
if lexer is not None: if lexer is not None:
try: try:
accuracy = lexer.analyse_text(text) accuracy = lexer.analyse_text(text)
except: # pragma: nocover except: # pragma: nocover
pass log.traceback(logging.DEBUG)
return lexer, accuracy return lexer, accuracy
@ -240,13 +240,14 @@ def get_language_from_json(language, key):
'languages', 'languages',
'{0}.json').format(key.lower()) '{0}.json').format(key.lower())
if os.path.exists(file_name):
try: try:
with open(file_name, 'r', encoding='utf-8') as fh: with open(file_name, 'r', encoding='utf-8') as fh:
languages = json.loads(fh.read()) languages = json.loads(fh.read())
if languages.get(language.lower()): if languages.get(language.lower()):
return languages[language.lower()] return languages[language.lower()]
except: except:
pass log.traceback(logging.DEBUG)
return None return None