fix: Loguru formatting and narrow exception handling#245
Merged
Conversation
There was a problem hiding this comment.
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
ExceptiontoOSErrorand adjust user-facing messages accordingly. - Update CLI tests to exercise
OSError/PermissionErrorpaths instead ofRuntimeError.
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.
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>
e3e69f6 to
ca2811b
Compare
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.
Changes
Fix Loguru formatting — replaced
%swith{}inparser.py:365so vanished-session warnings actually log the path and error.Replace broad
except Exceptionwith narrowexcept 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.Remove dead code —
except SystemExit: raisein thesessioncommand was dead code (SystemExitinherits fromBaseException, notException).Updated tests — error handling tests now use
OSError/PermissionError(operational errors) instead ofRuntimeError(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.