Repository navigation
fix(cli): surface backup path guard remedies in --json failures - #199562
Conversation
|
🦞👀 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 backup-path errors show their existing remedy on stderr when using --json. Example: Run openclaw backup verify "" --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a current backup diagnostic defect with a minimal shared-owner change and no actionable findings; required CI has not completed. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherBackup command actions send path arguments through shared validators, whose errors reach the CLI failure renderer for stderr diagnostics and JSON output. flowchart LR
A[Backup arguments] --> B[Backup command action]
B --> C[Shared path validators]
C --> D[Expected CLI error]
D --> E[CLI failure renderer]
E --> F[Stderr remedy]
E --> G[JSON failure envelope]
Technical reviewBest possible solution: Use the existing expected-error helper at both shared validators while preserving their messages and path-resolution semantics. Do we have a high-confidence way to reproduce the issue? Current-main validators, JSON-mode propagation and root rendering establish the failure path, matching the contributor's before/after built-CLI traces; this read-only review ran no target code. Is this the best way to solve the issue? This is the smallest complete repair: classify invalid arguments at their existing shared owner rather than adding catches or message matching in callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8f9bd10825ff. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests 0. Total +1 across 2 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:
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 15, 2026, 6:09 AM ET / 11:09 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Verified on head 420bfec against merge-base 6695768. Host isolation check: diff contains only src/commands/backup-shared.ts and its existing test file; no dependency, lifecycle, hook, or scripts changes. All product execution ran through ocx on the host, with task-owned HOME/state/config and profiles p199562base/p199562cand; no Gateway was started. Worktrunk hooks were disabled; ocx's normal install lifecycle ran. Source tier (Node + tsx): the real CLI passes the empty positional argument through register.backup.ts to backupVerifyCommand and resolveBackupArchivePath. Commands: The first and third commands printed generic failure plus a Doctor hint on base stderr. Candidate stderr prints respectively: The JSON stdout bytes and exit codes were identical in every before/after pair (cmp). Empty-path commands exit 1; the valid archive exits 0 with ok:true, assetCount:1 and entryCount:7. Text mode retains the existing missing-archive message. The nonexistent-archive control retains its original error. Successful verification has timing-dependent progress lines; its stdout is identical. No message text changes in the patch. Vitest-source: copied the candidate's existing backup-shared.test.ts to the base checkout: 6 blank-input cases fail because the thrown Error is not ExpectedCliError, while 6 path-resolution controls pass. Candidate: all 12 pass. No new tests or allocation file; production +3/-2, tests +2/-2 (net 0). Simplification: the existing expected-error helper at both shared owners is the smallest complete change; no extra catch layer or machinery. Contributor commit retained unchanged: SunnyShu [email protected] (human author and committer); no agent trailers. Related #195644 changes another behavior in the same function and is only a textual overlap. |
|
Full tier completed on 420bfec: |
|
Landed in e734174. Thanks @SunnyShu0925. |
…claw#199562) fix(cli): show the missing backup path error with --json A blank backup path, for example `openclaw backup verify "" --json`, threw a plain error from the shared backup path resolver, so the JSON failure printed only "The CLI command failed." and the doctor hint instead of the existing "Missing required <archive> value.". The resolver now throws the same messages through the existing expected-CLI-error path, as the other blank-argument checks do. Text mode, JSON stdout and exit codes are unchanged. No new text. Evidence: source tier with isolated state and no Gateway; a blank argument reaches the check unchanged. `backup verify ""` and a second backup caller with --json: base's stderr had only the generic failure and the doctor hint; this change prints the existing message. Text mode, the JSON stdout envelope and exit codes match on both, and a real archive path verifies the same. Vitest-source: the regression fails on base and 12 tests pass here; full build and packed smoke pass. Net 0 test lines. Receipts: openclaw#199562 (comment). Thanks @SunnyShu0925. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw backup verify "" --jsonexits 1, but stderr only prints the generic[openclaw] The CLI command failed.and a doctor hint — the actionable remedyMissing required <archive> value.reaches the text channel and the JSON stdout envelope, but never the--jsonstderr. This routes the two shared backup path guards through the existing expected-CLI-error owner so the remedy surfaces on every channel.resolveRequiredBackupPathandresolveBackupArchivePathinsrc/commands/backup-shared.tsthrow a plainErrorfor blank path values. The CLI failure renderer treats plain errors as unexpected, so--jsonstderr degrades to the generic two lines while the text channel prints the message. Five command families (backup verify/restore,backup create,backup git,backup sqlite,backup schedule) share these guards.throwExpectedCliError(...)fromsrc/cli/expected-cli-error.tsinstead ofthrow new Error(...)at both guards — the same owner conversion already merged for sibling CLI guards.src/commands/backup-shared.ts(one import + two throw sites); the existing blank-value unit case now assertsExpectedCliError(net 0 test lines).Why This Change Was Made
Best fix: yes — a two-line conversion at the shared owner covers every caller at once, using the canonical
ExpectedCliErrorcontract (message + humanOutput + machineOutput) that the failure renderer already understands. This is the same shape as the merged sibling conversions #199369, #199386, #198965, #198975, and #198861.Alternative: catching and reformatting the error in each of the five command actions — rejected because it duplicates the owner's policy at 10+ call sites and drifts; special-casing the message string in the JSON failure renderer — rejected because string matching is fragile and the owner already exists.
Risk: the failure is now classified as expected rather than unexpected, which is the intent (no doctor hint for a user input mistake). The envelope message, text output, and exit code are proven byte-identical, so scripts parsing stdout see no change. Blank
--outputonbackup createstill resolves to the default destination before reaching the guard (caller behavior unchanged); the conversion keeps the owner consistent for all labels.Related: #195644 (open, literal-path preservation) rewrites the resolution return of
resolveRequiredBackupPathand explicitly keeps the blank-value error unchanged; this PR converts that error's class without touching resolution semantics. The two are complementary:git merge-treeshows a single content conflict in that function body (the test file auto-merges), resolved by keeping his literal-path return and thisthrowExpectedCliErrorcall — whichever lands first, the other needs only that mechanical rebase.User Impact
Operators scripting backups with
--jsonnow see the actual remedy on stderr —Missing required <archive> value.,Missing required <snapshot> value.,Missing required --repository value.— instead of a generic failure that points atopenclaw doctor. Text-channel users see no difference.Evidence
node openclaw.mjs …, isolated scratch profile)backup verify "" --jsonstderr[openclaw] The CLI command failed.+ doctor hint (208 B)Missing required <archive> value.(163 B)backup sqlite verify " " --jsonstderrMissing required <snapshot> value.backup sqlite create --repository "" --jsonstderrMissing required --repository value.backup git create --repository "" --jsonstderrMissing required --repository value.backup verify ""text stderrMissing required <archive> value.backup verify "" --jsonstdout envelope{"ok":false,"error":{"type":"cli_error","message":"Missing required <archive> value."}}(112 B)backup verify /nonexistent-427.tar.gz(control, both channels)Archive does not exist…remedy, exit 1Two-arm built shipped matrix
Both arms built with
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup(exit 0 each, per-package node_modules links).--versionself-reports the arm identity:Every cell is a full product command run with
node openclaw.mjsunder an isolated chmod-700 scratch HOME/state/XDG_RUNTIME_DIR with the user bus cut, no credentials, no mocks: 5 commands × {text, --json} × {base, head} = 20 cells, all exit 1.Primary cell, verbatim stderr:
A trailing
log file append failedwarning from the scratch profile appears byte-identically in both arms' stderr and is omitted above; it is unrelated to the guard. The remedy message itself attests the guard was reached: the pre-action state-store guard would print a different refusal, andExpectedCliErrorintentionally carries no debug stack.cmpinvariants across arms (all pass):Built bundle attestation (the executed form, not just source):
Focused tests and mutation RED
backup-shared,backup-sqlite,backup-git,backup-verify,backup-restore,backup-schedule,backup-create— 184 passed, 1 pre-existing skip.ExpectedCliError(net 0 test lines; the remedy text stays pinned by thebackup-sqliteconsumer suite and the byte-identical envelope).backup-shared.tsreverted to base, all 6 blank-value cases fail withexpected error to be instance of ExpectedCliErrorwhile the 6 path-resolution cases stay green; restored and re-verified clean.oxfmt --checkclean on both files;oxlint0 findings (232 rules); targetedtscprogram over the two touched files: 0 errors in them (3 pre-existing environment errors elsewhere:JSON.rawJSONlib target, missingqrcodetypes).What was not tested
Open PR collision check
Searched today's open PRs by anchor keywords (backup remedy / Missing required backup / ExpectedCliError backup / resolveRequiredBackupPath / resolveBackupArchivePath) and by changed-file intersection across my 39 open PRs and the latest 60 community open PRs. The submission-time recheck surfaced #195644 (opened Nov 9, outside the latest-60 slice): it touches the same two files but fixes literal-path whitespace, not error classification — complementary, not a duplicate (see Related above). The recently merged #199367 (backup multi-core compression) touches
backup-restore.test.ts/backup-create-stream.tsonly — zero file overlap.