Skip to content

Address CodeQL code-quality alerts - #73

Merged
urucoder merged 1 commit into
mainfrom
codeql-quality-cleanup
Jul 28, 2026
Merged

Address CodeQL code-quality alerts#73
urucoder merged 1 commit into
mainfrom
codeql-quality-cleanup

Conversation

@Clamps251

Copy link
Copy Markdown
Collaborator

Closes the 20 open CodeQL code-quality alerts on main.

  • 12× py/empty-except — narrowed broad except Exception: pass blocks to the specific exception types the code can actually raise (OSError, serial.SerialException) and added an intent comment to each.
  • py/unused-local-variable — removed IMAGE_EXTS and K, plus 3 dead nonlocal declarations in xbee_master_collect.py.
  • py/unused-global-variable — removed sys_path / proc_path in rest_client.py.
  • py/use-of-exit-or-quit — swapped exit(1) for sys.exit(1) at two import-time bail-out sites in rest_client.py.
  • py/import-and-import-from — dropped from torch import Tensor in detection_utils.py; annotation sites use torch.Tensor.

No functional changes.

- 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.
Copilot AI review requested due to automatic review settings July 28, 2026 11:16
@Clamps251
Clamps251 requested a review from urucoder July 28, 2026 11:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 unnecessary global declaration.
  • Replaced exit(1) with sys.exit(1) for import-time bailouts in rest_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
urucoder merged commit 8b6aeb1 into main Jul 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants