Repository navigation
fix: return one complete JSON result for switch - #4345
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
When the cause of a failure lives in a typed error's fields, the JSON error loses it. GitError::WorktreeCreationFailed displays only its title, and the git output and leftover-branch hint live in fields that only Diagnostic::render shows. So the {error:#} fallback in handle_command_failure gives the caption and nothing else. I checked this against the built branch:
$ wt switch --create 'bad..name' --format=json --no-cd --yes 2>/dev/null
{"error":"Failed to create worktree for bad..name from base main"}
The same thing happens when worktree-path points through a regular file, the case test_switch_create_names_branch_left_by_failed_worktree_add covers. The JSON says creation failed but not why, and it doesn't mention the branch that git left behind. The comment on that branch says the outer caption alone shouldn't hide the actual cause, and here it does. A tool that reads only stdout has nothing to act on. One fix would be an ANSI-stripped render() for errors that implement Diagnostic. Another would be a dedicated plain-text detail for the JSON path.
codecov/patch is failing on one line: the CommandError::find_in branch in handle_command_failure (inline below).
|
@worktrunk-bot Please refresh this PR branch against current main and resolve its mechanical merge conflicts so it can get current CI. Preserve the proposed behavior and the current draft state, run the focused checks for the resulting diff, and report any conflict that requires a semantic or product decision. This requests branch maintenance; the outstanding maintainer review remains pending.
|
Conflicts: - src/git/error.rs: main's interrupt_signal already walks the whole error chain (covering AlreadyDisplayed contexts) with the new physical_signal/cancellation fields; took main's version and kept the branch's AlreadyDisplayed unit assertion. - tests/integration_tests/step_alias.rs: main moved test_alias_approval_decline to approval_pty.rs, superseding the branch's stdin-race fix; took main's side. Integration fixups: - Pass the new switch_json argument at the two handle_command_failure call sites main added (help pager: false; signal-forwarder startup: switch_json). - Update JSON switch tests for main's behavior: upfront branch-name validation, "Failed to execute <program>" spawn errors, "exit code N" child exits, and wt re-raising SIGTERM/SIGINT instead of exiting 143/130.
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is failing on one line, but the gap isn't new. The merge passes switch_json to the CommandOperation::start() error arm in main (src/main.rs#L1324), so Codecov now counts that line as part of the patch. The same arm is already uncovered on main, at line 1285 in the bf1d348c4 report. That arm only runs if a command operation is already active or the signal handler fails to register, so no test I can see reaches it. Under the AGENTS.md Coverage rule, a failing patch check needs a maintainer's explicit approval before merge, so I've withdrawn my earlier approval until a maintainer makes that call.
I found no problems in the conflict resolutions or test updates, and test (linux|macos|windows) pass at this head.
codecov/patch fails at the current head and needs a maintainer's explicit approval to merge.
|
I merged current main into this branch and pushed it as 2412272. CI passes at that head except Conflicts
Changes needed for the merge to build
Local checks: build, |
One rule replaces four message branches: the error string is what stderr shows, or the child's exit when the child spoke for itself. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The diff itself looks good. Moving the JSON error onto format_command_error keeps the git output, typed-diagnostic hints, and context chain that the removed branches carried. It also stops a diagnostic that renders empty from producing "error": "".
codecov/patch is still failing at this head, on one line: the CommandOperation::start() error arm (src/main.rs#L1316). This is the same gap the earlier review described. The arm is uncovered on main too, and the PR only adds the switch_json argument to it. AGENTS.md (Coverage) requires explicit maintainer approval to merge with a failing patch check, so I've withdrawn my approval until a maintainer makes that call.
codecov/patch failing — needs maintainer approval per AGENTS.md Coverage.
JSON switches now emit one result after synchronous work, including any --execute command, finishes. Accepted invocations return the existing success fields, or an object with an
errorstring when target discovery, configuration, directory directives, or execution fails. Execute output goes to stderr, and child errors retain exit and signal metadata. Typed Git diagnostics retain captured Git details and recovery hints, including commands for a branch left behind after failed worktree creation. Argument errors and picker cancellation produce no JSON; background hooks remain independent.Validation: the full project gate passed (5,028 tests, one skipped), plus focused checks covering early and late failures, child output and signals, picker behavior, and plain output. Generated help, documentation synchronization and build, and independent review passed. The change also removes a synthetic stdin write from an existing noninteractive alias-refusal test that raced with process exit.