fix: handle SyntaxError gracefully in ast_analyzer#742
Open
jyotish6699 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug in the AST analyzer where invalid Python source code causes
analyze()to raise aSyntaxErrorinstead of returning a structured analyzer issue.The analyzer currently crashes when malformed Python code is passed to
ast.parse(). This behavior interrupts analysis and requires callers to handle unexpected exceptions.With this change, syntax errors are handled gracefully and returned through the analyzer's existing issue-reporting system.
Changes Made
SyntaxErrorhandling aroundast.parse()Example
Before
Result:
After
The analyzer returns a structured issue describing the syntax error instead of crashing.
Related Issue
Fixes #741
Testing
Added:
test_analyze_handles_syntax_errorVerified:
Notes
This issue is different from #466.
Issue #466 focuses on adding test coverage for existing AST analyzer behaviors, while #741 addresses a separate bug where invalid Python syntax can cause the analyzer to raise an unhandled exception and terminate analysis.
This PR implements the bug fix and corresponding test coverage for Issue #741.