Address CodeQL code-quality alerts - #73
Merged
Merged
Conversation
- Narrow 10 broad `except Exception: pass` blocks to the specific exception types actually raised (OSError / serial.SerialException) and add an intent comment to each. Two other empty-except blocks were already narrow; those just get a comment. - Remove dead code: `IMAGE_EXTS`, `K`, `sys_path`, `proc_path`, and the `global clf_ort_sessions` no-op declaration. - Trim 3 dead `nonlocal` declarations in xbee_master_collect.py where the names were only read or mutated (never rebound). - Replace 2 top-level `exit(1)` calls with `sys.exit(1)` in rest_client.py. - Drop the redundant `from torch import Tensor` in detection_utils.py and use `torch.Tensor` in the 4 annotation sites instead. No functional changes. Verified end-to-end on the test Pi: sparrow container recreated with the new code, no ImportError/traceback in any log, and an injected test JPEG round-trips through inference and uploads to the server with 200.
There was a problem hiding this comment.
Pull request overview
This PR addresses CodeQL code-quality alerts across Sparrow’s runtime/utility modules by tightening exception handling, removing unused variables, and making a small exit-handling adjustment.
Changes:
- Narrowed previously broad “ignore-and-continue” exception handlers to specific expected exception types (e.g.,
OSError,serial.SerialException) and added intent comments. - Removed unused locals/globals (
IMAGE_EXTS,K,sys_path,proc_path) and an unnecessaryglobaldeclaration. - Replaced
exit(1)withsys.exit(1)for import-time bailouts inrest_client.py.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sparrow/xbee_master_collect.py | Narrows ignored serial buffer/close exceptions; removes unused locals/nonlocal declarations. |
| sparrow/xbee_configure.py | Narrows ignored serial close exception during probing. |
| sparrow/utils/detection_utils.py | Removes unused Tensor import and unused local K; switches annotations to torch.Tensor. |
| sparrow/rest_client.py | Uses sys.exit(1) and removes unused globals; narrows temp-file cleanup exception. |
| sparrow/model_update.py | Narrows temp-file cleanup exception types; adds intent comments. |
| sparrow/inference.py | Removes unnecessary global declaration for dict mutation. |
| sparrow/email_server.py | Adds clarifying comment for intentional KeyboardInterrupt handling. |
| sparrow/audio.py | Narrows temp-file cleanup exception type and documents best-effort behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
135
to
145
| try: | ||
| ser.reset_input_buffer() | ||
| except Exception: | ||
| except (serial.SerialException, OSError): | ||
| # Buffer reset is best-effort on freshly-opened ports; ignore. | ||
| pass | ||
|
|
||
| try: | ||
| ser.reset_output_buffer() | ||
| except Exception: | ||
| except (serial.SerialException, OSError): | ||
| # Buffer reset is best-effort on freshly-opened ports; ignore. | ||
| pass |
urucoder
approved these changes
Jul 28, 2026
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.
Closes the 20 open CodeQL code-quality alerts on
main.except Exception: passblocks to the specific exception types the code can actually raise (OSError,serial.SerialException) and added an intent comment to each.IMAGE_EXTSandK, plus 3 deadnonlocaldeclarations inxbee_master_collect.py.sys_path/proc_pathinrest_client.py.exit(1)forsys.exit(1)at two import-time bail-out sites inrest_client.py.from torch import Tensorindetection_utils.py; annotation sites usetorch.Tensor.No functional changes.