Skip to content

Unmatched parentheses raises IndexError instead of an informative error message  #532

@onkar

Description

@onkar
Python 3.11.8 (main, Aug 16 2024, 10:27:21) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.metadata import version
>>> import sql_metadata
>>> version('sql_metadata')
'2.11.0'
>>> from sql_metadata import Parser
>>> Parser("SELECT arrayJoin(tags.key)) FROM foo").query_type
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 98, in query_type
    _ = self.tokens
        ^^^^^^^^^^^
  File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 167, in tokens
    self._determine_closing_parenthesis_type(token=token)
  File "/Users/onkardeshpande/code/snuba/.venv/lib/python3.11/site-packages/sql_metadata/parser.py", line 901, in _determine_closing_parenthesis_type
    last_open_parenthesis = self._open_parentheses.pop(-1)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: pop from empty list
>>>

There is a mismatching parenthesis in SELECT arrayJoin(tags.key)) but the error message is vague. We use ClickHouse at the backend and it shows a correct error on the unmatched parentheses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions