fix(scripts): visit_Try walker now visits ALL except handlers

The audit script's visit_Try had a bug where the
\or child in handler.body\ loop was OUTSIDE the
\or handler in node.handlers\ loop. So \handler\ was bound
to the LAST handler, and only the last handler's body was walked.
Raises in non-last except handlers were missed (e.g.,
src/rag_engine.py:31 was not in the audit findings).

The fix moves the inner loop inside the outer loop so each
handler's body is walked. Both the FIRST and LAST handler raises
are now detected.

Adds tests/test_audit_exception_handling_bug_fixes.py with 2
tests for the walker behavior (first-handler raise, middle-handler
raise in a 3-handler try).
This commit is contained in:
ed
2026-06-17 18:53:25 -04:00
parent 92cea9c483
commit eb9b8aad2e
2 changed files with 229 additions and 2 deletions
+2 -2
View File
@@ -771,8 +771,8 @@ class ExceptionVisitor(ast.NodeVisitor):
for handler in node.handlers:
category, hint = self._classify_except(handler, node)
self._add_finding("EXCEPT", handler.lineno, self._snippet(handler), category, hint)
for child in handler.body if node.handlers else []:
self.visit(child)
for child in handler.body:
self.visit(child)
for child in node.orelse:
self.visit(child)
for child in node.finalbody: