Skip to content

Commit 42087ed

Browse files
authored
Preemptively fix unknown errors of Python AST parsing coming from astroid and ast libraries (#3027)
1 parent 2fd066a commit 42087ed

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/databricks/labs/ucx/source_code/python/python_ast.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
NodeNG,
2626
parse,
2727
Uninferable,
28-
AstroidSyntaxError,
2928
)
3029

3130
from databricks.labs.ucx.source_code.base import (
@@ -77,9 +76,7 @@ def maybe_parse(cls, code: str) -> MaybeTree:
7776
root = parse(code)
7877
tree = Tree(root)
7978
return MaybeTree(tree, None)
80-
except AstroidSyntaxError as e:
81-
return cls._definitely_failure('syntax-error', code, e)
82-
except SystemError as e:
79+
except Exception as e: # pylint: disable=broad-exception-caught
8380
# see https://github.com/databrickslabs/ucx/issues/2976
8481
return cls._definitely_failure('system-error', code, e)
8582

@@ -89,7 +86,7 @@ def _definitely_failure(message_code: str, source_code: str, e: Exception) -> Ma
8986
None,
9087
Failure(
9188
code=message_code,
92-
message=f"Failed to parse code `{source_code}`: {e}. Report this as an issue on UCX GitHub.",
89+
message=f"Failed to parse code `{source_code}`: {type(e)}: {e}. Report this as an issue on UCX GitHub.",
9390
# Lines and columns are both 0-based: the first line is line 0.
9491
start_line=0,
9592
start_col=0,

tests/unit/source_code/notebooks/test_cells.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_graph_builder_parse_error(
195195
problems = analyser.build_graph()
196196
codes = {_.code for _ in problems}
197197

198-
assert codes == {'syntax-error'}
198+
assert codes == {'system-error'}
199199

200200

201201
def test_parses_python_cell_with_magic_commands(simple_dependency_resolver, mock_path_lookup) -> None:

0 commit comments

Comments
 (0)