Skip to content

Unhandled exceptions break the --json contract #25

Closed

Description

@abruption

The contract

--json is supposed to emit exactly one {"ok": ...} line. run_remote() depends on it — it parses the remote's stdout and reports unexpected output when parsing fails. The whole remote path rests on this.

main() catches only CcPeerError and KeyboardInterrupt. Anything else escapes as a traceback: stdout stays empty, stderr gets a multi-line dump, and run_remote folds that entire dump into a single error string. Neither a human nor a parser can read the result.

Three reachable paths

discover() doesn't guard the directory walk. Individual files are wrapped in (OSError, ValueError), but directory.glob("*.json") isn't. is_dir() passing doesn't mean readable — a sudo'd run under a different uid, or NFS permissions, raises PermissionError straight through.

Binary on stdin. cat some.png | cc-peer send --to x - → UnicodeDecodeError.

Missing message argument hangs. cc-peer send --to X with no message and a TTY falls into sys.stdin.read() and waits with no prompt. Ctrl-D produces an empty string and only then the "refusing to send an empty message" error. An agent running this through a Bash tool hangs until its timeout — the worst version, since nothing indicates what it's waiting for.

Fix

  • except Exception fallback in main() that still emits JSON under --json
  • Wrap the glob in discover()
  • Detect sys.stdin.isatty() with no message argument and fail immediately with a usage hint

Acceptance criteria

  • Every failure path emits parseable JSON under --json
  • An unreadable sessions directory reports rather than tracebacks
  • Binary stdin reports rather than tracebacks
  • send --to X with no message and a TTY exits at once
  • Tests cover the exit codes and the JSON shape on failure — main(argv) is already injectable

Activity

  1. added
    bug
    on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions