Skip to content

Commit

Permalink
Only add ellipsis to NotJSONError message if message is truncated (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschroll committed Jan 13, 2023
1 parent bbd0f83 commit 5fc0e8d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nbformat/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def parse_json(s, **kwargs):
try:
nb_dict = json.loads(s, **kwargs)
except ValueError as e:
message = f"Notebook does not appear to be JSON: {s!r}"
# Limit the error message to 80 characters. Display whatever JSON will fit.
raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[:77] + "...") from e
if len(message) > 80:
message = message[:77] + "..."
raise NotJSONError(message) from e
return nb_dict


Expand Down

0 comments on commit 5fc0e8d

Please sign in to comment.