mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 14:24:18 +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:
|
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:
|
with open(filename) as f:
|
||||||
notebook_contents = json.load(f)
|
notebook_contents = json.load(f)
|
||||||
|
except json.JSONDecodeError as exc:
|
||||||
|
print(f'{filename}: Failed to load')
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
cells = notebook_contents['cells']
|
cells = notebook_contents['cells']
|
||||||
return_value = 0
|
return_value = 0
|
||||||
for cell in cells:
|
for cell in cells:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue