[K9VULN-13253] Panic on error node fix#878
[K9VULN-13253] Panic on error node fix#878gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits intomainfrom
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: b037789 | Docs | Datadog PR Page | Give us feedback! |
There was a problem hiding this comment.
Pull request overview
Fixes a panic in the Python static import analyzer when tree-sitter produces malformed AST nodes (e.g., ERROR nodes without a field name) inside import_statements, ensuring analysis continues and still extracts valid imports.
Changes:
- Add a runtime guard in
parse_import_statementto skip named children that are not in the"name"field (preventingERRORnodes from reachingparse_field_child_node). - Add a unit test covering malformed syntax (
import foo, + bar) to ensure parsing does not panic and still returns valid imports.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ae6715b to
7df1bb1
Compare
7df1bb1 to
49e09d8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jasonforal
left a comment
There was a problem hiding this comment.
Nice! Small nits, because the language feels a bit Claude-y
What problem are you trying to solve?
The analyzer panics when processing Python files with invalid nodes
What is your solution?
parse_field_child_nodenow returnsOption<MaybeAliased>instead of panicking on unexpected node types. All 3 callers handleNonegracefullyAlternatives considered
An alternative was to skip files at the tree level by checking
has_error()andhas_missing()on the root node inanalyze.rsbut this was too broad as it would skip an entire file for any parse error, even when most of the file is validWhat the reviewer should know
Added two unit tests that first assert the input has an
ERRORnode and then verifies that no panic occurs and the correct imports are returned