Skip to content

Commit 2746090

Browse files
prepare-sync: warn on close-cleanup failure (codeql)
PR-C.3 review fixup. The ``except Exception: pass`` after the best-effort ``close_method()`` call tripped CodeQL's ``py/empty-except`` rule on two surfaces (code-quality + advanced security). Cleanup is intentionally best-effort — a raise here MUST NOT propagate or break sibling observers' dispatch — but swallowing silently makes the rare cleanup-failure case invisible. Replace the empty pass with ``except Exception as close_error:`` followed by a ``warnings.warn`` mentioning the cleanup-failure. Same isolation contract preserved (no propagation, no sibling-blocking) but the swallow is now observable. CodeQL ``py/empty-except`` cleared on both surfaces.
1 parent dae3da2 commit 2746090

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/openarmature/graph/observer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,17 @@ def _dispatch(context: _InvocationContext, event: NodeEvent) -> None:
423423
if close_method is not None:
424424
try:
425425
close_method()
426-
except Exception:
427-
pass
426+
except Exception as close_error:
427+
# Cleanup is best-effort: a raise here MUST NOT
428+
# propagate or block sibling observers. Surface
429+
# via ``warnings.warn`` so the swallow is at
430+
# least observable if it ever fires (CodeQL
431+
# py/empty-except clears on this surface too).
432+
warnings.warn(
433+
f"observer prepare_sync close cleanup raised "
434+
f"{type(close_error).__name__}: {close_error}",
435+
stacklevel=2,
436+
)
428437
warnings.warn(
429438
"observer prepare_sync returned an awaitable; "
430439
"prepare_sync MUST be sync (define as `def`, not "

0 commit comments

Comments
 (0)