mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
handle file reading exceptions
This commit is contained in:
parent
31d9774748
commit
38bd34f828
2 changed files with 15 additions and 1 deletions
|
|
@ -42,6 +42,12 @@ def check_file_for_debug_statements(filename):
|
||||||
print('\t' + traceback.format_exc().replace('\n', '\n\t'))
|
print('\t' + traceback.format_exc().replace('\n', '\n\t'))
|
||||||
print()
|
print()
|
||||||
return 1
|
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 = ImportStatementParser()
|
||||||
visitor.visit(ast_obj)
|
visitor.visit(ast_obj)
|
||||||
if visitor.debug_import_statements:
|
if visitor.debug_import_statements:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
import io
|
||||||
import tokenize
|
import tokenize
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
double_quote_starts = tuple(s for s in tokenize.single_quoted if '"' in s)
|
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):
|
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)
|
line_offsets = get_line_offsets_by_line_no(contents)
|
||||||
|
|
||||||
# Basically a mutable string
|
# Basically a mutable string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue