Skip to content

Commit

Permalink
Changing message for TokenError
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvimoharir committed Jul 21, 2021
1 parent 705e027 commit fc40194
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/black/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,20 @@ def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) -
result = drv.parse_string(src_txt, True)
break

except (TokenError, ParseError) as err:
if isinstance(err, ParseError):
lineno, column = err.context[1]
else:
lineno, column = err.args[1]
except ParseError as pe:
lineno, column = pe.context[1]
lines = src_txt.splitlines()
try:
faulty_line = lines[lineno - 1]
except IndexError:
faulty_line = "<line number missing in source>"
exc = InvalidInput(f"Cannot parse: {lineno}:{column}: {faulty_line}")

except TokenError as te:
lineno, column = te.args[1]
lines = src_txt.splitlines()
exc = InvalidInput(f"Cannot parse: {lineno}:{column}: Unexpected EOF")

else:
raise exc from None

Expand Down

0 comments on commit fc40194

Please sign in to comment.