Repository navigation
fix(cli): keep backup archive verification remedies in --json error output - #199891
SunnyShu0925 wants to merge 1 commit into
Conversation
…utput prepareBackupArchive wrapped every archive-verification failure in a plain Error, so in JSON mode stderr fell back to the generic doctor banner while the structured remedy survived only in the stdout envelope. Convert the shared wrapper to throwExpectedCliError so verify, restore, and create --verify keep the operator remedy on stderr, with messages, exit codes, the JSON envelope, and text-mode output unchanged.
|
🦞👀 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: blocked before merge. What this changesThis PR preserves archive-verification recovery instructions on stderr when backup commands use --json. Example: Run openclaw backup verify /tmp/missing.tar.gz --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: it fixes a current diagnostic defect through the existing shared owner, supplied CLI proof demonstrates the result, and no actionable patch defect was found. Priority: P3 Before merge
FindingsNone. Agent review detailsHow this fits togetherBackup verification validates archive inputs for verify, restore, creation, and recovery callers; its shared error reaches the CLI renderer, which produces human diagnostics and machine-readable failures. flowchart TD
A[Backup CLI commands] --> B[Shared archive preparation]
B --> C[Archive and snapshot validation]
C --> D[Expected CLI error]
D --> E[Root failure renderer]
E --> F[Recovery instructions on stderr]
E --> G[JSON failure on stdout]
Technical reviewBest possible solution: Use the existing expected-error classification at the shared archive summary boundary while preserving validation, recovery wording, and machine output. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically routes the plain archive error to generic stderr in JSON mode, consistent with the contributor's supplied before/after CLI traces; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete repair: classify the existing shared summary through ExpectedCliError rather than changing global rendering or duplicating fixes across archive guards and callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d0e09e419d7e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests -2. Total -2 across 3 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 Reviewed November 15, 2026, 9:22 PM ET / November 16, 2026, 02:22 UTC. |
|
Thanks for the work here. We're closing this one along with the other open per-command |
fix(cli): show the existing failure message for plain errors in --json mode `runCommandWithRuntime` rethrew every plain error in JSON mode, so the root renderer printed only the generic "The CLI command failed." plus the Doctor hint on stderr, while text mode printed the error's own (redacted) message. Contributors had been patching this one command at a time by converting individual throws to expected errors. JSON mode now shows the same redacted message text mode already shows, once in the shared wrapper; the JSON stdout envelope, exit codes and text-mode output are unchanged. Commands that fail outside the wrapper (for example `models auth login` conflicts and `attach` target resolution) are not covered. No new text. Evidence: host, isolated state. 76 CLI runs across eight command flows (including `backup verify`, `backup remote`, `skills list/check/info` and `migrate plan/apply`), twice per side: base prints the generic failure in --json mode, this change prints the existing message; text failure output, JSON stdout and exit codes are identical across 150 comparisons. 156 unit and 124 consumer tests pass; full build and installed packed smoke pass. CI reds are inherited from main (receipt: #199970 (comment)). Supersedes the closed per-command PRs #199891, #199900, #199910 and #199448. Co-authored-by: Ayaan Zaidi <[email protected]>
fix(cli): show the existing failure message for plain errors in --json mode `runCommandWithRuntime` rethrew every plain error in JSON mode, so the root renderer printed only the generic "The CLI command failed." plus the Doctor hint on stderr, while text mode printed the error's own (redacted) message. Contributors had been patching this one command at a time by converting individual throws to expected errors. JSON mode now shows the same redacted message text mode already shows, once in the shared wrapper; the JSON stdout envelope, exit codes and text-mode output are unchanged. Commands that fail outside the wrapper (for example `models auth login` conflicts and `attach` target resolution) are not covered. No new text. Evidence: host, isolated state. 76 CLI runs across eight command flows (including `backup verify`, `backup remote`, `skills list/check/info` and `migrate plan/apply`), twice per side: base prints the generic failure in --json mode, this change prints the existing message; text failure output, JSON stdout and exit codes are identical across 150 comparisons. 156 unit and 124 consumer tests pass; full build and installed packed smoke pass. CI reds are inherited from main (receipt: openclaw#199970 (comment)). Supersedes the closed per-command PRs openclaw#199891, openclaw#199900, openclaw#199910 and openclaw#199448. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw backup verify <missing-archive> --jsonprints the full operator remedy to stdout's JSON envelope but only a generic two-line fallback (The CLI command failed. / For help, run openclaw doctor.) to stderr, so an operator reading the terminal in JSON mode has no actionable next step. Converting the archive-verification summary error toExpectedCliErrorkeeps the same remedy text on stderr in JSON mode without changing the stdout envelope or exit code.prepareBackupArchive()wraps every archive-verification failure in a plainError. In JSON moderunCommandWithRuntimerethrows plainErrors, and the root renderer only emits a generic failure line to stderr; the structured message survives only in the stdout envelope.throw new Error(...)inprepareBackupArchive()withthrowExpectedCliError(...).ExpectedCliErrorcarrieshumanOutputandmachineOutput, soformatCliFailureLines/formatCliJsonFailurerender the same remedy to stderr in both text and JSON modes.src/commands/backup-verify.tsimportsthrowExpectedCliErrorand uses it at the singleprepareBackupArchivesummary wrapper. A single-use intermediateSetis inlined at its one call site so the file stays within the repository line-cap ratchet after the new import.src/commands/backup-verify.test.tsfolds the two existing failure cases (missing/directory and invalid header) to assert the rethrownExpectedCliErrorshape directly instead ofruntime.error/runtime.exit.test/cli-json-stdout.e2e.test.tsadds a stderr-remedy assertion to the existing JSON-failure case.Why This Change Was Made
prepareBackupArchiveis the canonical owner introduced to wrap every archive-verification failure so that direct verify,backup restore, andbackup create --verifyshare one diagnostic boundary. Converting the wrapper's throw preserves that design and covers manifest, path-header, and SQLite snapshot failures in one change instead of per-guard edits.ExpectedCliError. Editing the CLI renderer instead would change behavior for every plainErrorin the codebase. Both are wider or less complete.ExpectedCliErrorextendsError, so shared callers that propagate or format the rejected error see the same message. Internal callers (create--verify, remote, doctor schema guard, update worker) already handle failures through genericformatErrorMessage/diagnostics, so the subtype change is additive. The only observable change is JSON-mode stderr now carries the remedy that was already in the stdout envelope.User Impact
Operators running
backup verify(orbackup restore/backup create --verify) against a bad archive in--jsonmode now see the same actionable remedy on stderr that text mode already showed, instead of a generic doctor hint. The JSON stdout envelope and exit code are unchanged, so machine consumers are unaffected.Evidence
Before/after comparison
backup verify <missing> --jsonstderr[openclaw] The CLI command failed.+ doctor hintBackup archive verification failed: <missing>. Archive does not exist. Check the path and run \openclaw backup verify ` again.`backup verify <directory> --jsonstderr... Archive must be a regular file. Choose a backup archive created by \openclaw backup create` and try again.`backup verify <invalid.tar.gz> --jsonstderr... Archive is not a valid OpenClaw backup. ... Choose another archive or create a new one with \openclaw backup create`.`backup verify <missing>(text, control)backup restore <missing> --target <dir> --jsonstderr{ ok: false, error: { type: "cli_error", message: "<full remedy>" } }, exit 1End-to-end shipped proof
Both arms built independently from the same parent commit with
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup; each launcher self-reports the identical commit vianode openclaw.mjs --version. Isolated scratchHOME/state/config, no credentials or mocks.Built-bundle self-proof:
Real command runs. Two symmetric harness-noise lines are omitted because they appear identically on both arms and are unrelated to the fix: the Node 24.19.0 security warning, and
[openclaw] log file append failed; records dropped ... file=openclaw-2026-11-16.log(the scratch HOME has no writable log path):Text-mode control (unchanged between arms):
Shared
backup restorechannel confirms the wrapper fix reaches all callers:Invariants verified with
cmp: JSON stdout envelopes identical across arms for missing/directory/invalid/restore; text-mode stderr identical; exit codes identical (all 1).Regression tests
src/commands/backup-verify.test.ts: the two existing failure cases now assertname: "ExpectedCliError"plusmessage/humanOutput/machineOutput. Base arm (production reverted) fails these assertions withname: "Error"; candidate arm passes. Full file: 40 passed, 1 skipped.backup-verify-completeness,backup-verify.utf8,backup-legacy-hardlinks,backup-restore: 72 passed.doctor-update-schema-guard,database-migration-capture: 35 passed (sharedverifyBackupArchivecallers).test/cli-json-stdout.e2e.test.ts: existing JSON-failure case now also asserts stderr contains the remedy; passes on candidate.Open PR collision check
Searched all open pull requests by changed-file list (full snapshot, not only title/body keywords). No open PR modifies the
prepareBackupArchivewrapper or the error-classification path insrc/commands/backup-verify.ts. Two open PRs (#194566, #192698) touch the same file but only the hardlink-target resolution block (around lines 541-610), disjoint from this change at the verification-summary wrapper.Related: #199869 converts nine restore-input guards in
src/commands/backup-restore.tsand deliberately leaves the shared archive-verification path generic; its file set is disjoint from this PR, so either merge order needs no rebase. After both land,backup restorewith a bad archive also keeps the remedy on stderr, which extends that PR's missing-archive control cell by design.What was not tested
backup create --verifyandbackup remotewere not exercised end-to-end with a built CLI in this run; they share the sameverifyBackupArchive/prepareBackupArchivewrapper and are covered by unit tests.