Skip to content

fix(cli): render non-Error failures instead of [object Object] - #1404

Merged
willwashburn merged 3 commits into
mainfrom
claude/issue-1383-fix-dq8mzr
Jul 31, 2026
Merged

fix(cli): render non-Error failures instead of [object Object]#1404
willwashburn merged 3 commits into
mainfrom
claude/issue-1383-fix-dq8mzr

Conversation

@willwashburn

@willwashburn willwashburn commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1383.

packages/cli/src/cli/index.ts rendered top-level rejections with err instanceof Error ? err.message : String(err). A non-Error rejection — a protocol-shaped object like { status: 401 } from a broker client — printed [object Object] and nothing else. An Error with an empty message printed nothing at all, since the handler only wrote when the string was truthy.

Adds describeError(unknown): string (packages/cli/src/cli/lib/describe-error.ts):

  • Error → its message; when the message is empty, its name, or name: <cause> when it carries a cause
  • object → the message/error text plus status/code context (invalid workspace key (status 401, code unauthorized)), else compact JSON ({"status":401})
  • primitive → String(value); never returns an empty string, never returns [object Object]

The JSON fallback runs through the existing redactSecrets, so a rejection payload carrying a workspace key or token cannot leak into stderr, and it truncates at 500 chars so a large payload can't flood the terminal. Cycles render as [circular] rather than throwing.

Call sites updated:

  • the top-level catch in cli/index.ts
  • attach-broker.ts mapBrokerSdkFailure, which is where the reported attach 401 turned into [object Object] as the failure message that callers then printed
  • the node agent attach paths (attach-native.ts, attach-drive.ts, attach-passthrough.ts)
  • the per-module toErrorMessage/errorMessage/extractChildFailure helpers (core-maintenance.ts, broker-lifecycle.ts, mcp/action-tools.ts, node-provider-child.ts)

broker-lifecycle.ts already exported a describeError — the cause-chain walker that unwraps TypeError: fetch failed into ECONNREFUSED etc. It's the broker-start specialization, so it's renamed to describeErrorWithCause and now builds on the shared formatter (gaining non-Error handling for free).

On the issue's root-cause companion: the broker client paths already reject with typed HarnessDriverProtocolErrors throughout @agent-relay/harness-driver (HTTP failures, WS input-stream failures, timeouts, closes), and I found no site in this repo that throws or rejects with a bare object. So this ships the backstop formatter only; if the { status: 401 } value originated outside these paths, the formatter now surfaces enough detail to identify where.

Test Plan

  • Tests added/updated — packages/cli/src/cli/lib/describe-error.test.ts covers Error/empty-message/cause, protocol-shaped objects, nested error objects, credential redaction, cycles, truncation, primitives, and an explicit "never renders [object Object]" case
  • npx vitest run packages/cli — 879 passed, 11 skipped, 0 failed
  • npm run typecheck — clean
  • npm run lint — no new warnings (only pre-existing complexity/naming warnings)

Screenshots

n/a


Generated by Claude Code

Review in cubic

A top-level rejection that isn't an Error — e.g. a protocol-shaped
`{ status: 401 }` from a broker client — printed `[object Object]` and
nothing else, and an Error with an empty message printed nothing at all.

Add `describeError(unknown): string`: Error -> message (falling back to
name/cause when empty), object -> `message`/`error` text with `status`/
`code` context or compact credential-redacted JSON, primitive -> String.
Use it at the top-level catch, the attach paths, the broker failure
mapper (which reported `[object Object]` as the failure message), and the
per-module error-message helpers.

`broker-lifecycle`'s exported `describeError` is the cause-chain
specialization, renamed to `describeErrorWithCause` and now built on the
shared formatter.

Closes #1383

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKFr7pXffb5LVaP5pjo8bG
@willwashburn
willwashburn requested a review from khaliqgant as a code owner July 31, 2026 00:58
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e572757-4d2c-4c70-b549-2db6be9bd49b

📥 Commits

Reviewing files that changed from the base of the PR and between caaaf9f and 32b4623.

📒 Files selected for processing (3)
  • packages/cli/src/cli/lib/describe-error.test.ts
  • packages/cli/src/cli/lib/describe-error.ts
  • packages/cloud/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli/src/cli/lib/describe-error.test.ts
  • packages/cli/src/cli/lib/describe-error.ts

📝 Walkthrough

Walkthrough

A shared describeError formatter now renders CLI failures consistently. It handles structured non-Error values, empty errors, nested causes, redacted credentials, cyclic objects, oversized payloads, and fallback values. CLI and broker paths use the formatter.

Changes

CLI error formatting

Layer / File(s) Summary
Shared error formatter
packages/cli/src/cli/lib/describe-error.ts, packages/cli/src/cli/lib/describe-error.test.ts, packages/cli/src/cli/lib/index.ts
Exports describeError to render unknown values as non-empty single-line text. Handles Error messages and names, nested causes, protocol objects (extract message or error text, append status and code), primitives, and fallbacks. Applies credential redaction, cycle tolerance, and length limits. Comprehensive tests cover all paths.
Broker cause-chain integration
packages/cli/src/cli/lib/broker-lifecycle.ts, packages/cli/src/cli/lib/broker-lifecycle.test.ts, packages/cli/src/cli/lib/attach-broker.ts
Separates broker cause-chain formatter into describeErrorWithCause. General broker messages use describeError. Background and foreground startup handlers use describeErrorWithCause for nested details. Attach-broker SDK failure mapping uses describeError. Tests updated to target renamed function.
CLI failure-path adoption
packages/cli/src/cli/index.ts, packages/cli/src/cli/lib/attach-drive.ts, packages/cli/src/cli/lib/attach-native.ts, packages/cli/src/cli/lib/attach-passthrough.ts, packages/cli/src/cli/lib/core-maintenance.ts, packages/cli/src/cli/lib/node-provider-child.ts, packages/cli/src/cli/mcp/action-tools.ts, CHANGELOG.md
Top-level handler, attach variants (native, drive, passthrough), maintenance, child-process, and MCP error paths replace ad hoc Error.message and String(err) conversions with describeError. Changelog documents the shared CLI error formatting fix.
Cloud redact package export
packages/cloud/package.json
Exports @agent-relay/cloud/redact subpath with type and ESM targets for credential-redaction imports.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: khaliqgant

Suggested labels: size:L

Poem

I'm a rabbit with errors tucked neat,
Redacting secrets before they repeat.
Bare objects now speak, empty errors grow clear,
Cause chains hop safely from ear to ear.
"Unknown error" waits when no words appear. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary CLI fix for non-Error failures rendered as [object Object].
Description check ✅ Passed The description includes the required summary, test plan, test results, and screenshots section, with clear implementation details.
Linked Issues check ✅ Passed The changes satisfy issue #1383 by adding shared formatting for non-Error and empty-message failures across the required CLI paths.
Out of Scope Changes check ✅ Passed The changes remain aligned with issue #1383, including the redaction export needed by the shared error formatter.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-1383-fix-dq8mzr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a08d755da3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/src/cli/lib/describe-error.ts
Comment thread packages/cli/src/cli/lib/describe-error.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/cli/lib/describe-error.ts`:
- Around line 99-112: Update toCompactJson so its JSON.stringify fallback
handles BigInt values and does not return the generic Object.prototype.toString
tag for plain objects. When serialization fails, produce a useful
constructor/tag-based description of the unserializable value while preserving
the existing redaction and truncation behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b396f9ee-4623-44c1-b1d0-fe537bf30278

📥 Commits

Reviewing files that changed from the base of the PR and between 5677683 and a08d755.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • packages/cli/src/cli/index.ts
  • packages/cli/src/cli/lib/attach-broker.ts
  • packages/cli/src/cli/lib/attach-drive.ts
  • packages/cli/src/cli/lib/attach-native.ts
  • packages/cli/src/cli/lib/attach-passthrough.ts
  • packages/cli/src/cli/lib/broker-lifecycle.test.ts
  • packages/cli/src/cli/lib/broker-lifecycle.ts
  • packages/cli/src/cli/lib/core-maintenance.ts
  • packages/cli/src/cli/lib/describe-error.test.ts
  • packages/cli/src/cli/lib/describe-error.ts
  • packages/cli/src/cli/lib/index.ts
  • packages/cli/src/cli/lib/node-provider-child.ts
  • packages/cli/src/cli/mcp/action-tools.ts

Comment thread packages/cli/src/cli/lib/describe-error.ts
claude added 2 commits July 31, 2026 03:07
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKFr7pXffb5LVaP5pjo8bG
…readable

Review follow-ups on the describeError backstop:

- A server error payload is free to echo the credential that was sent to
  it, and the `message`/`error` text is lifted out whole — key-name
  redaction never sees it. Run every branch's output through
  `redactCredentialValues`, the same value-pattern masking the CLI's
  commander output boundary already applies.
- `JSON.stringify` throws on BigInt, so `{ status: 401, retryAfter: 30n }`
  hit the catch and returned `[object Object]` — the exact rendering this
  module exists to eliminate. Serialize BigInt/function/symbol members
  through a replacer, and name a genuinely unserializable value by its
  constructor instead of the Object tag.

`@agent-relay/cloud` gains a `./redact` subpath so the formatter can take
the masking helper without the package barrel, which pulls in auth and
child-process spawning and broke the doctor suite's module mocks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKFr7pXffb5LVaP5pjo8bG
@willwashburn
willwashburn merged commit 693f23f into main Jul 31, 2026
41 checks passed
@willwashburn
willwashburn deleted the claude/issue-1383-fix-dq8mzr branch July 31, 2026 03:25
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.

Top-level CLI failures from non-Error rejections render as [object Object]

2 participants