Fix signal handler cleanup bug when startup fails early #54
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-45-signal-handler-startup-failure"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #45.
Summary
Initializes
previous_sigterm_handler = Noneinrun_combined_runtimebefore thetryblock, so thefinallycleanup is safe when startup fails before the SIGTERM handler is registered.Adds a regression test that simulates early startup failure (mapping validation error) and asserts the function returns the correct exit code (2) without raising
UnboundLocalError.Root cause
src/rgb_aura/runtime.pyhadprevious_sigterm_handlerassigned only inside thetryblock, after_connect_and_validate()succeeded. Thefinallyblock referenced it unconditionally. If any of the following raised before the assignment:_connect_and_validate()device mapping validation error_build_runtime_zones()validation error...then the
finallyblock raisedUnboundLocalError: cannot access local variable 'previous_sigterm_handler', which masked the original startup exception and made troubleshooting harder.Fix
One-line addition: initialize the variable to
Nonebefore thetry. The existingif previous_sigterm_handler is not None:guard in thefinallynow correctly skips the SIGTERM restore when the handler was never registered.Regression test
tests/test_runtime.py::test_run_combined_runtime_returns_mapping_error_when_validation_fails_connect_and_validateto raiseDeviceMappingError.run_combined_runtimewith otherwise valid runtime args.Without the fix, this test would fail with
UnboundLocalErrorpropagating from thefinallyblock. With the fix, it passes cleanly.Verification before commit
python -m pytest tests/— 1 passed.ruff check src/ tests/— all checks passed.ruff format --check src/ tests/— 23 files already formatted.python -m rgb_aura.main --dry-run --dry-run-events 3— clean run, all 14 animations registered, scheduler preview produces events normally.Branch workflow
developfix/issue-45-signal-handler-startup-failuredevelopmain.