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

Preemptively fix unknown errors of Python AST parsing coming from astroid and ast libraries #3027

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/databricks/labs/ucx/source_code/python/python_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
NodeNG,
parse,
Uninferable,
AstroidSyntaxError,
)

from databricks.labs.ucx.source_code.base import (
Expand Down Expand Up @@ -77,9 +76,7 @@ def maybe_parse(cls, code: str) -> MaybeTree:
root = parse(code)
tree = Tree(root)
return MaybeTree(tree, None)
except AstroidSyntaxError as e:
return cls._definitely_failure('syntax-error', code, e)
except SystemError as e:
except Exception as e: # pylint: disable=broad-exception-caught
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nfx : Would have like to see a comment that motivates why we have a broad exception

# see https://github.com/databrickslabs/ucx/issues/2976
return cls._definitely_failure('system-error', code, e)

Expand All @@ -89,7 +86,7 @@ def _definitely_failure(message_code: str, source_code: str, e: Exception) -> Ma
None,
Failure(
code=message_code,
message=f"Failed to parse code `{source_code}`: {e}. Report this as an issue on UCX GitHub.",
message=f"Failed to parse code `{source_code}`: {type(e)}: {e}. Report this as an issue on UCX GitHub.",
# Lines and columns are both 0-based: the first line is line 0.
start_line=0,
start_col=0,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/source_code/notebooks/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_graph_builder_parse_error(
problems = analyser.build_graph()
codes = {_.code for _ in problems}

assert codes == {'syntax-error'}
assert codes == {'system-error'}


def test_parses_python_cell_with_magic_commands(simple_dependency_resolver, mock_path_lookup) -> None:
Expand Down
Loading