HallerPatrick / HallerPatrick/frosch

Parsing error when exception occurs inside except handler

Open
#33 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
198
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Example script:

```python
from frosch import hook

hook()

try:
1/0
except Exceptoin:
pass
```

Output:

```
Error in sys.excepthook:
Traceback (most recent call last):
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 115, in ParseCodeToTree
tree = parser_driver.parse_string(code, debug=False)
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 103, in parse_string
return self.parse_tokens(tokens, debug)
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 71, in parse_tokens
if p.addtoken(type, value, (prefix, start)):
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/parse.py", line 162, in addtoken
raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=1, value='except', context=('', (1, 0))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 121, in ParseCodeToTree
tree = parser_driver.parse_string(code, debug=False)
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 103, in parse_string
return self.parse_tokens(tokens, debug)
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/driver.py", line 71, in parse_tokens
if p.addtoken(type, value, (prefix, start)):
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/lib2to3/pgen2/parse.py", line 162, in addtoken
raise ParseError("bad input", type, value, context)
lib2to3.pgen2.parse.ParseError: bad input: type=1, value='except', context=('', (1, 0))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/frosch/parser.py", line 180, in format_line
formatted_line, _ = FormatCode(line)
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/yapf_api.py", line 147, in FormatCode
tree = pytree_utils.ParseCodeToTree(unformatted_source)
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 127, in ParseCodeToTree
raise e
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/yapf/yapflib/pytree_utils.py", line 125, in ParseCodeToTree
ast.parse(code)
File "/home/alex/.pyenv/versions/3.8.0/lib/python3.8/ast.py", line 47, in parse
return compile(source, filename, mode, flags,
File "", line 1
except Exceptoin :
^
SyntaxError: invalid syntax

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/alex/.cache/pypoetry/virtualenvs/book-E12DIahb-py3.8/lib/python3.8/site-packages/frosch/parser.py", line 196, in format_line
raise ParseError("Could not parse line: {}".format(line)) from error
frosch.parser.ParseError: Could not parse line: except Exceptoin :

Original exception was:
Traceback (most recent call last):
File "/home/alex/.config/JetBrains/PyCharm2020.3/scratches/scratch_1099.py", line 6, in
1/0
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/alex/.config/JetBrains/PyCharm2020.3/scratches/scratch_1099.py", line 7, in
except Exceptoin:
NameError: name 'Exceptoin' is not defined
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.