Skip to content

Commit

Permalink
Preemptively fix unknown errors of Python AST parsing coming from `as…
Browse files Browse the repository at this point in the history
…troid` and `ast` libraries (#3027)
  • Loading branch information
nfx authored Oct 21, 2024
1 parent 2fd066a commit 42087ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
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
# 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

0 comments on commit 42087ed

Please sign in to comment.