handle file reading exceptions

This commit is contained in:
Kevin James 2017-08-15 23:03:55 -07:00
parent 31d9774748
commit 38bd34f828
2 changed files with 15 additions and 1 deletions

View file

@ -42,6 +42,12 @@ def check_file_for_debug_statements(filename):
print('\t' + traceback.format_exc().replace('\n', '\n\t'))
print()
return 1
except Exception:
print('{} - Caught exception while reading file'.format(filename))
print()
print('\t' + traceback.format_exc().replace('\n', '\n\t'))
print()
return 1
visitor = ImportStatementParser()
visitor.visit(ast_obj)
if visitor.debug_import_statements:

View file

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import argparse
import io
import tokenize
import traceback
double_quote_starts = tuple(s for s in tokenize.single_quoted if '"' in s)
@ -32,7 +33,14 @@ def get_line_offsets_by_line_no(src):
def fix_strings(filename):
contents = io.open(filename).read()
try:
contents = io.open(filename).read()
except Exception:
print('{} - Caught exception while reading file'.format(filename))
print()
print('\t' + traceback.format_exc().replace('\n', '\n\t'))
print()
return 1
line_offsets = get_line_offsets_by_line_no(contents)
# Basically a mutable string