diff --git a/pre_commit_hooks/debug_statement_hook.py b/pre_commit_hooks/debug_statement_hook.py index c5ca387..69a498a 100644 --- a/pre_commit_hooks/debug_statement_hook.py +++ b/pre_commit_hooks/debug_statement_hook.py @@ -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: diff --git a/pre_commit_hooks/string_fixer.py b/pre_commit_hooks/string_fixer.py index 3523e8a..e5e72b3 100644 --- a/pre_commit_hooks/string_fixer.py +++ b/pre_commit_hooks/string_fixer.py @@ -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