Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax-error cannot be emitted, raises InvalidMessageError instead #7522

Closed
jacobtylerwalls opened this issue Sep 24, 2022 · 1 comment · Fixed by #7553
Closed

syntax-error cannot be emitted, raises InvalidMessageError instead #7522

jacobtylerwalls opened this issue Sep 24, 2022 · 1 comment · Fixed by #7553
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@jacobtylerwalls
Copy link
Member

Bug description

When AstroidSyntaxError is caught and a syntax-error is raised, an assertion fails when a line number is lacking.

I suppose we could either raise "fatal" instead or expand _SCOPE_EXEMPT to also include syntax-error.

Configuration

No response

Command used

python3 -m pylint coverage.tracer

Pylint output

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tokenize.py", line 330, in find_cookie
    line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/astroid/builder.py", line 105, in file_build
    stream, encoding, data = open_source_file(path)
  File "/opt/homebrew/lib/python3.9/site-packages/astroid/builder.py", line 40, in open_source_file
    encoding = detect_encoding(byte_stream.readline)[0]
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tokenize.py", line 371, in detect_encoding
    encoding = find_cookie(first)
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tokenize.py", line 335, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for '/opt/homebrew/lib/python3.9/site-packages/coverage/tracer.cpython-39-darwin.so'

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

Traceback (most recent call last):
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1014, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/opt/homebrew/lib/python3.9/site-packages/astroid/manager.py", line 117, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/opt/homebrew/lib/python3.9/site-packages/astroid/builder.py", line 114, in file_build
    raise AstroidSyntaxError(
astroid.exceptions.AstroidSyntaxError: Python 3 encoding specification error or unknown encoding:
invalid or missing encoding declaration for '/opt/homebrew/lib/python3.9/site-packages/coverage/tracer.cpython-39-darwin.so'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/.../pylint/pylint/__main__.py", line 10, in <module>
    pylint.run_pylint()
  File "/Users/.../pylint/pylint/__init__.py", line 35, in run_pylint
    PylintRun(argv or sys.argv[1:])
  File "/Users/.../pylint/pylint/lint/run.py", line 207, in __init__
    linter.check(args)
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 691, in check
    ast_per_fileitem = self._get_asts(fileitems, data)
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 706, in _get_asts
    ast_per_fileitem[fileitem] = self.get_ast(
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1019, in get_ast
    self.add_message(
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1307, in add_message
    self._add_one_message(
  File "/Users/.../pylint/pylint/lint/pylinter.py", line 1202, in _add_one_message
    message_definition.check_message_definition(line, node)
  File "/Users/.../pylint/pylint/message/message_definition.py", line 116, in check_message_definition
    raise InvalidMessageError(
pylint.exceptions.InvalidMessageError: Message E0001 must provide line, got None

Expected behavior

E001
or perhaps a Fatal error

Pylint version

pylint 2.16.0-dev
astroid 2.12.2
Python 3.9.13 (main, May 24 2022, 21:13:51) 
[Clang 13.1.6 (clang-1316.0.21.2)]

OS / Environment

No response

Additional dependencies

coverage==6.4.4

@jacobtylerwalls jacobtylerwalls added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 24, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 24, 2022
@Pierre-Sassoulas
Copy link
Member

Should we simply use 0 as the line number ? I'm surprised mypy did not warn us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants