Skip to content

fix: JSON output follow-ups from --format=json rollout - #2001

Merged
max-sixty merged 2 commits into
mainfrom
json-output
Apr 8, 2026
Merged

max-sixty merged 2 commits into
mainfrom
json-output

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 8, 2026 •

Copy link
Copy Markdown
Owner

Four targeted fixes identified as follow-ups from the --format=json rollout (#1969, #1998):

  1. Sort stability in partition_log_files_json — added filename tiebreaker to match render_log_table's sort. Without this, entries with identical timestamps could appear in non-deterministic order in JSON output.

  2. for-each error field always present on failure — previously, the "error" field only appeared for SpawnFailed errors, not ExitCode. Consumers parsing the JSON had to handle two shapes. Now both variants include "error": "exit code N" for ExitCode, "spawn failed: ..." for SpawnFailed, "killed by signal" for signal termination. Error formatting lives in CommandError::Display impl with a unit test covering all three variants.

  3. Test: config show --format=json outside a git repo — verifies that project path/config are null when not in a git repository.

  4. Test: multi-remove --format=json with current worktree — covers the plans.current code path where the current worktree appears in the multi-remove target list (deferred to last in output).

This was written by Claude Code on behalf of Maximilian Roos

- Add filename tiebreaker to partition_log_files_json sort (matches
  render_log_table's sort stability)
- Make for-each `error` field always present on failure, not just
  SpawnFailed — ExitCode now includes "exit code N" or "killed by signal"
- Add test for config show --format=json outside a git repo
- Add test for multi-remove --format=json with current worktree

Co-Authored-By: Claude <noreply@anthropic.com>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codecov/patch is failing on line 112 of src/commands/for_each.rs — the format!("spawn failed: {e}") expression inside the SpawnFailed arm. This arm was already uncovered on main; the PR only changed the return value format (from Some(e.clone()) to format!("spawn failed: {e}")).

The SpawnFailed path requires the user's shell binary to be unspawnable (the command itself is wrapped by the shell, so a nonexistent command gives exit code 127 via ExitCode, not SpawnFailed). This makes it impractical to test without fragile environment manipulation.

This is a false positive — pre-existing uncovered code where only the format string changed.

Move error message formatting to Display impl and exit code extraction
to exit_code() method on CommandError. Add unit test covering all three
variants (SpawnFailed, ExitCode, signal-killed).

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty
max-sixty merged commit 65e58d3 into main Apr 8, 2026
25 checks passed
@max-sixty
max-sixty deleted the json-output branch April 8, 2026 04:54
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.

2 participants