Skip to content

fix(scope): harden error handling; claudescope-py uses Parquet for query() - #29

Merged
rylero merged 3 commits into
mainfrom
worktree-cached-spinning-raccoon
Jul 6, 2026
Merged

rylero merged 3 commits into
mainfrom
worktree-cached-spinning-raccoon

Conversation

@rylero

@rylero rylero commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixed a real bug: CLI error responses double-encoded the daemon's JSON error body into another {"error","code"} envelope, and </>/& in any error text or field name came out as <-style garbage (encoding/json HTML-escapes by default). Errors are now flat, clean text.
  • Fixed a related regression risk: the daemon's specific error code (e.g. SESSION_NOT_FOUND) was only recoverable by unwrapping that nested JSON blob; it's now carried through cleanly via a typed APIError so both the CLI's own JSON output and claudescope-py get the real code.
  • Fixed a silent data-loss bug: query-multi --format csv/parquet --union true dropped the per-session errors list entirely when some sessions in the batch failed (row-shaped output has no place to put them). Now rejects the request instead, pointing the caller at --format json.
  • claudescope-py's Session.query() now fetches results as --format parquet instead of JSON, parsed via pd.read_parquet() — faster for large results and preserves native bool/float64/string dtypes instead of relying on pandas' JSON type inference. query_multi()'s union mode stays on JSON since it needs the per-session errors list alongside the rows.
  • Verified the previously-flagged "connect hangs on unreachable host" concern is not a real bug — bounded at ~10s by the existing http.Client.Timeout, confirmed via a live test against a black-holed IP.

Test plan

  • go build ./..., go vet ./..., go test ./... all pass
  • pytest (16 tests) passes in python/
  • Live end-to-end verification against the rebuilt binary + real pandas: dtypes preserved through session.query(), error codes (SESSION_NOT_FOUND) propagate correctly, union-mode errors still surface via JSON, --format correctly rejects a union query with partial failures

🤖 Generated with Claude Code

rylero added 3 commits July 6, 2026 06:35
…erved, mangled <>& fixed

Three related bugs in CLI error plumbing:

- cli/client.go: DoRequest embedded the daemon's raw JSON error body
  verbatim as the error string, so main.go's writeErrorAndExit stuffed
  an already-JSON blob into another {"error","code"} envelope. Now
  DoRequest decodes the daemon's {error,code} and returns a clean
  message via a new APIError type.
- main.go/client.go: that same flattening was previously dropping the
  daemon's specific error code (e.g. SESSION_NOT_FOUND) in favor of a
  hardcoded COMMAND_FAILED at the top level, since the code lived only
  inside the nested JSON blob. APIError now carries Code through to
  writeErrorAndExit so callers (including claudescope-py) get the real
  code back.
- encoding/json HTML-escapes < > & by default; any error message or
  field name containing them came out as <-style garbage. Daemon
  responses and all CLI-side json.Marshal call sites now go through
  SetEscapeHTML(false), replacing the ad-hoc string-replace workaround
  that only covered runHelp's output.

Also: query-multi --format csv/parquet silently dropped the "errors"
list when used with --union true, since row-shaped output has nowhere
to put per-session failures. It now rejects the request instead,
pointing the caller at --format json.
Session.query() now calls the CLI with --format parquet and loads the
result via pd.read_parquet() instead of parsing --format json through
pandas' dict-list constructor. Faster for large results and preserves
native bool/float64/string dtypes rather than relying on JSON type
inference.

query_multi()'s union mode stays on JSON: --format can't carry the
per-session "errors" list alongside row data (see the Go-side fix in
the previous commit), and this wrapper needs both together.

Adds _cli.invoke_bytes() for raw (non-JSON) stdout, used by the new
Parquet path; on a non-zero exit it still decodes the CLI's
{"error","code"} JSON body the same way invoke() does. Also drops
invoke()'s now-dead double-JSON-unwrap workaround, since the daemon
error is no longer double-encoded on the Go side.

Adds pyarrow as a required dependency (needed by pandas to read/write
Parquet).
@rylero
rylero force-pushed the worktree-cached-spinning-raccoon branch from d423b12 to e7708d2 Compare July 6, 2026 13:36
@rylero
rylero marked this pull request as ready for review July 6, 2026 13:36
@rylero
rylero merged commit 1039dc2 into main Jul 6, 2026
1 check passed
@rylero
rylero deleted the worktree-cached-spinning-raccoon branch July 6, 2026 13:37
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.

1 participant