Repository navigation
fix(cli): surface blank --account/--channel remedies in both lanes - #198965
Conversation
The --account and --channel option parsers ran during Commander coercion, before the action wrapper that renders CLI errors, so a plain Error lost its remedy text in the human lane and turned the JSON lane into a generic failure. Throw through ExpectedCliError so both lanes report the actual message.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes blank account and channel selectors print their specific validation error in both text and JSON modes. Example: Run openclaw channels capabilities --account "".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current CLI diagnostic defect with a focused change using the existing error-rendering owner; no introduced bugs were found, and hosted CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCommander and channel command actions pass selector values through shared validators; expected errors reach the root CLI renderer, which produces stderr diagnostics and JSON failure output. flowchart TD
A[CLI arguments] --> B[Commander option parsing]
B --> C[Shared selector validators]
B --> D[Channel command actions]
D --> C
C --> E[Expected CLI error]
E --> F[Root failure renderer]
F --> G[Stderr and JSON output]
Technical reviewBest possible solution: Keep both existing selector guards and route their failures through the canonical expected-error helper as this PR does. Do we have a high-confidence way to reproduce the issue? Current-main source demonstrates the failure path, and supplied built-CLI before/after output corroborates it; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch is the smallest complete fix: both producers use the existing dependency-light error owner, preserving selector rules and avoiding renderer special cases. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 508dbdfe0d81. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests -1. Total +3 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 14, 2026, 11:21 AM ET / 16:21 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Independent proof at 364f15a (base d98f18f), host through ocx, tiers vitest-source + source. Host eligibility checked with All commands used isolated task home/state/config and explicit p198965 profiles. No Gateway started. The boundary test verifies rejection before preAction/startup; these parsers run during Commander coercion, before action/Gateway access. Selection/name-to-ID code unchanged. Receipts (stdout/stderr captured together in local logs): Command correction: channels resolve requires an entry and its --channel option does not use parseChannelSelector. That case is intentionally an unchanged control; --account there and --channel on message send exercise the changed guards. Initial missing-entry attempts are setup-only, not proof. Production +6/-2; tests +8/-9. Contributor commit preserved. PR author SunnyShu0925 differs from commit author AND committer: |
|
Landed in 8b8204b. Thanks @SunnyShu0925. |
…penclaw#198965) fix(cli): show the blank --account and --channel errors A blank --account or --channel (for example an unset shell variable) made the account and channel selectors throw a plain error, so commands such as `openclaw channels capabilities`, `channels resolve --account`, `directory self`, `directory peers list` and `message send` printed only "The CLI command failed." and the doctor hint instead of the existing "--account must not be blank" or "--channel must not be blank". The selectors now throw the same messages through the existing expected-CLI-error path. Selection and name resolution are unchanged. No new text. Evidence: vitest-source, the updated tests fail on base and pass here. Source tier with isolated state, text and --json: base printed only the generic failure; this change prints the existing "must not be blank" line, with exit codes and JSON unchanged. `channels resolve --channel ""` does not use this selector and is unchanged on both; valid values behave the same on both. Net -1 test lines. Receipts: openclaw#198965 (comment). Thanks @SunnyShu0925. Co-authored-by: 0668000539 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw channels capabilities --account ""exits 1 and prints only[openclaw] The CLI command failed.plus[openclaw] For help, run `openclaw doctor`.— the actual reason,--account must not be blank, never reaches the terminal, and the same happens forchannels resolve,directory self,directory peers listandmessage sendwith a blank--accountor--channel(the usual result of an unset shell variable). This change routes both blank-input guards through the CLI's expected-failure owner so the remedy is printed in the default text mode and in--jsonmode.parseAccountSelector(src/commands/channels/account-selector.ts:5) andparseChannelSelector(src/commands/channels/channel-selector.ts:5) threw a plainError. They are registered as Commander option coercion callbacks (channels-cli.ts:243/263,directory-cli.ts:89/91,register.message.ts:161/163), so the throw happens during option parsing, before the action wrapper that prints CLI errors, and the root renderer folds it into the generic failure pairthrowExpectedCliError()fromsrc/cli/expected-cli-error.ts, the owner already used for the same guard shape insrc/commands/status-json-command.ts:32,src/commands/export-trajectory.ts:91andsrc/cli/capability-cli/shared.ts:54throwstatement per selector file (net +4 production lines: two imports, two blank separators, two line-neutral throw swaps); the existing rejection cases insrc/cli/account-selector-boundary.test.tsandsrc/cli/channels-account-selector.integration.test.tsnow assert the rejection type (net −1 test line, no new file, no new exports)--jsonenvelope, the behavior of a non-blank value, and every failure that is not one of these two guardsWhy This Change Was Made
The complete fix is to make these two bootstrap argument parsers raise the error type the root renderer already understands, so one owner serves both output lanes regardless of where the guard is called from.
runCommandWithRuntime(src/cli/cli-utils.ts:39-57) prints through the runtime only when the error is not anExitError, JSON mode is off, and the error is not anExpectedCliError; otherwise it rethrows andsrc/cli/failure-output.tsprintshumanOutput. A plainErrorraised during coercion never reaches that wrapper at all, which is why both lanes lost the text.Best fix: yes —
src/cli/expected-cli-error.tsstates "Bootstrap argument parsers use this module; keep runtime dependencies out", and these two files are exactly that; the conversion adds no runtime dependency, no formatter and no second rendering rule. Alternatives rejected: special-casing these two strings in the root renderer (duplicate policy for one command family), moving the checks into each action body (six call sites reimplement one guard), or leaving them because a--jsonconsumer can parse stdout (the error stream still contradicts the envelope and the text mode prints nothing).Risk and boundaries: the only behavior beyond the remedy restoration is that an
ExpectedCliErroris rethrown pastrunChannelsCommandWithDanger, so theChannel login failed:/Channel logout failed:label is no longer prepended for these two guards (measured below, exit code and stdout unchanged). Non-goals: the independent--agentblank guards,dead-letters.ts's own selector owner, and any runtime failure that is not an argument check stay on their current paths.User Impact
A mistyped or unset
--account/--channelnow explains itself:openclaw channels capabilities --account "",channels resolve --account "" abc,directory self --channel "",directory peers list --account " "andmessage send --target x --account " " --dry-runprint--account must not be blank/--channel must not be blankon stderr, in the default text mode where previously the reason appeared nowhere, and in--jsonmode where previously only the stdout envelope carried it. Scripts and agent logs that read stderr get the same explanation the envelope already had. No new flags, no config keys, no documentation changes; both remedy strings are already documented indocs/cli/directory.mdanddocs/cli/pairing.md.Compatibility
--account/--channelstill select the default; non-blank values behave exactly as before; exit codes stay 1; the--jsonenvelope is byte-identical; text-mode stdout stays empty;channels add/channels removeoutput is byte-identicalhooks --agentguards that also throw outside the action wrapper, fix(cli): surface capability flag-guard remedies in --json failures #198471 did the same for the capability flag guards and fix(cli): surface message option-guard remedies in --json failures #198861 for the message option guards; this converts the remaining channels/directory selector guardsChannel login failed:/Channel logout failed:label for failures other than these two guards, no Windows or macOS run, no gateway or channel-provider runEvidence
Both arms are real builds of the shipped CLI, run end to end through the launcher.
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartupwas run in a frozenorigin/maincheckout atd98f18ff7c3and in this head364f15a8e61; each launcher identifies its own build (OpenClaw 2026.11.3 (d98f18f)andOpenClaw 2026.11.3 (364f15a)). Every cell below isnode openclaw.mjs …underenv -iwithHOME,XDG_RUNTIME_DIRandOPENCLAW_STATE_DIRpointed at a fresh mode-0700 scratch directory — no gateway, no credentials, no mocks, no source-level harness. Sixteen cells per arm, all exit 1 in both arms. Each stderr stream also carries a Node TLS advisory and a log-file notice that are byte-identical across arms; sizes are whole-stream, quoted lines are the payload.node openclaw.mjs …)origin/maind98f18f364f15achannels capabilities --account ""(text)The CLI command failed.+For help, run \openclaw doctor`.`; stdout 0 B--account must not be blank; stdout 0 Bchannels capabilities --account "" --jsoncmpidenticalchannels resolve --account "" abc(text and--json)--account must not be blankin both modes; stdoutcmpidenticaldirectory self --channel ""(text and--json)--channel must not be blankin both modes; stdoutcmpidenticaldirectory peers list --account " "(text and--json)--account must not be blankin both modes; stdoutcmpidenticalmessage send --target x --account " " --dry-run(text and--json)--account must not be blankin both modes; stdoutcmpidenticalmessage send --target x --channel "" --dry-run(text and--json)--channel must not be blankin both modes; stdoutcmpidenticalchannels capabilities --account default(non-blank)--account requires a specific --channel. Run openclaw channels list to choose one.channels add --channel telegram --account ""channels login --account ""Channel login failed: --account must not be blankchannels logout --account ""Channel logout failed: --account must not be blankBASE build, default text mode — the reason is missing from every stream:
HEAD build, same command — remedy restored, same exit code:
HEAD build,
--jsonstdout of that same command — identical to BASE:{ "ok": false, "error": { "type": "cli_error", "message": "--account must not be blank" } }The shipped bundles carry exactly this change and nothing else. BASE chunk
dist/channel-selector-8Io11J60.mjs:HEAD chunk
dist/channel-selector-CMlB-vmp.mjs(the account chunk is symmetric):cmpacross the two builds confirms the blast radius: all six--jsonenvelopes (106 B), all six text-mode stdout streams (0 B), the non-blank control (457 B) and bothchannels addstreams (402 B / 173 B) are byte-identical. The twelve coercion stderr cells and the two wrapper-label cells are the only differences.Regression tests, folded into the existing cases of the two suites that already cover these guards (net −1 test line, no new file, no new exports):
The three coercion-lane rejections fail on the thrown type; the eight action-lane rejections fail because BASE swallows the guard inside
runCommandWithRuntimeand resolves while HEAD rethrows it to the root renderer — which is why the shippedchannels addcell stays byte-identical even though its test now asserts the rejection. The four passing cases are the omitted-account default-selection paths, unchanged.Consumer suites covering the six commands, the renderer and the same option topology, all green on HEAD:
Formatting and lint on the four changed files are clean: the repository formatter reports
All matched files use the correct format, andoxlintwith the repository config reportsFound 0 warnings and 0 errorson 259 rules.Open PR collision check, re-run against the submission-day open-PR snapshot: a changed-file sweep over the newest 150 open PRs returns no PR touching any of the four files, nor
src/cli/expected-cli-error.ts,src/cli/cli-utils.ts,src/cli/failure-output.tsorsrc/cli/channels-cli.ts. Keyword searches forparseAccountSelector,parseChannelSelectorandthrowExpectedCliErrorreturn #183099 (channels start/stop), #190470 (dead-letters), #193704 (audit--agent), #197626 (gateway status--url), #191233, #191237, #198329, #198333 and #198345 — all with zero file overlap with this change.What was not tested: a full-graph typecheck was not run locally, so the typed lanes are left to CI on this head. The
cliStartupbuild profile stops atcheck-cli-bootstrap-importswithagents/identity-file.worker.js: 240 evaluated modules exceeds budget 220— the identical assertion on the frozen BASE build and on HEAD, i.e. pre-existing in this environment and unrelated to these two files;tsdownemitteddist/entry.json both arms and the launcher runs it, which is what every cell above exercises. Thetest/cli-json-stdout.*.e2e.test.tssuites cover sibling flags (--agent,--command-cwd) rather than these guards and were not run. No Windows or macOS run, and no run against a live channel provider.