Repository navigation
fix: handle unhandled exceptions so --json always emits valid JSON - #33
Merged
Merged
Conversation
Three paths broke the --json contract:
1. discover() raised PermissionError when the sessions directory was
unreadable — now catches it and returns an empty list.
2. read_message() called sys.stdin.read() on a TTY when no message was
given, hanging forever — now detects isatty() and errors immediately.
Binary stdin causing UnicodeDecodeError is also caught.
3. Any other uncaught exception produced a raw traceback instead of
JSON — main() now has a catch-all that formats it as
{"ok": false, "error": "..."}.
Closes #25
Merged
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.
Problem
Three exception paths break the
--jsoncontract — callers get a raw traceback instead of parseable JSON:discover()raisesPermissionErrorwhen~/.claude/sessions/is unreadableread_message()callssys.stdin.read()on a TTY when no message is given, hanging forever; binary stdin raisesUnicodeDecodeError{"ok": false, ...}Fix
discover(): catchPermissionErroronglob()and return an empty listread_message(): detectisatty()and error immediately; catchUnicodeDecodeErroronstdin.read()main(): addexcept Exceptioncatch-all that formats as JSON when--jsonis setTests
test_main_catches_unexpected_exception_json: RuntimeError → JSON outputtest_main_catches_unexpected_exception_human: RuntimeError → stderrtest_discover_survives_permission_error: PermissionError → empty listtest_rejects_tty_stdin: TTY → CcPeerErrortest_catches_binary_stdin: UnicodeDecodeError → CcPeerErrorCloses #25