Add error handling

This commit is contained in:
cyyc1 2022-10-06 01:21:45 -07:00
parent 3df7b7ac8e
commit 405a904906

View file

@ -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: