Skip to content

fix: Loguru formatting and narrow exception handling#245

Merged
microsasa merged 3 commits intomainfrom
fix/code-review-cleanup
Mar 22, 2026
Merged

fix: Loguru formatting and narrow exception handling#245
microsasa merged 3 commits intomainfrom
fix/code-review-cleanup

Conversation

@microsasa
Copy link
Owner

Changes

  1. Fix Loguru formatting — replaced %s with {} in parser.py:365 so vanished-session warnings actually log the path and error.

  2. Replace broad except Exception with narrow except OSError — removed blanket exception handlers from all 4 CLI commands (summary, session, cost, live). Filesystem errors on data files get a friendly message. Programming bugs crash loudly with full tracebacks.

  3. Remove dead codeexcept SystemExit: raise in the session command was dead code (SystemExit inherits from BaseException, not Exception).

  4. Updated tests — error handling tests now use OSError/PermissionError (operational errors) instead of RuntimeError (programming bugs).

Rationale

Broad exception handlers masked programming errors by converting them into generic Error: ... messages. The new approach: catch only what we expect (filesystem errors on session data), let everything else surface.

Copilot AI review requested due to automatic review settings March 22, 2026 08:01
Copy link

Copilot AI left a comment

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 improves operational error reporting and logging by fixing Loguru message formatting and narrowing CLI exception handling to avoid masking programming errors, with corresponding test updates.

Changes:

  • Fix Loguru warning formatting in session parsing so log arguments render correctly.
  • Narrow CLI command exception handling from Exception to OSError and adjust user-facing messages accordingly.
  • Update CLI tests to exercise OSError/PermissionError paths instead of RuntimeError.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/copilot_usage/parser.py Fixes Loguru warning formatting for skipped/vanished sessions.
src/copilot_usage/cli.py Narrows exception handling to filesystem errors and adjusts control flow around rendering.
tests/copilot_usage/test_cli.py Updates error-handling tests to align with narrower exception handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sasa Junuzovic and others added 3 commits March 22, 2026 01:07
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Removed broad except-Exception blocks that swallowed programming errors.
Added narrow except-OSError catches around session data access only —
filesystem errors on data files get a friendly message, programming
bugs crash loudly.

Also removes dead 'except SystemExit: raise' from session command.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ert no traceback

- Remove redundant FileNotFoundError (subclass of OSError) in parser.py
- Wrap parse_events() in session command with OSError catch to skip unreadable files
- Add 'Traceback not in output' assertions to all error handling tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa force-pushed the fix/code-review-cleanup branch from e3e69f6 to ca2811b Compare March 22, 2026 08:08
@microsasa microsasa merged commit baaf40a into main Mar 22, 2026
4 checks passed
@microsasa microsasa deleted the fix/code-review-cleanup branch March 22, 2026 08:09
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.

2 participants