mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-25 12:54:28 +00:00
Add error handling
This commit is contained in:
parent
3df7b7ac8e
commit
405a904906
1 changed files with 33 additions and 25 deletions
|
|
@ -8,9 +8,17 @@ from pre_commit_hooks.util_string_fixer import fix_strings_in_file_contents
|
|||
|
||||
|
||||
def fix_strings(filename: str) -> int:
|
||||
if not filename.endswith('.ipynb'):
|
||||
print(f'{filename}: not a Jupyter notebook file')
|
||||
return 1
|
||||
|
||||
try:
|
||||
with open(filename) as f:
|
||||
notebook_contents = json.load(f)
|
||||
|
||||
except json.JSONDecodeError as exc:
|
||||
print(f'{filename}: Failed to load')
|
||||
return 1
|
||||
else:
|
||||
cells = notebook_contents['cells']
|
||||
return_value = 0
|
||||
for cell in cells:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue