gastownhall/beads · error

%w: %s

Error message

%w: %s

What it means

worktreeRemovalGit.output runs a pinned git command and captures stdout. On failure it checks for exec.ExitError and, if git wrote anything to stderr, appends it: `"%w: <stderr>"`. The wrapped error is the exec.ExitError (non-zero git exit status); the message gives git's own diagnostic. All worktree-removal plumbing (list, inspect, ref validation, object-size checks) funnels through here.

Solutions

  1. Read the stderr text after the colon — it is git's own diagnosis
  2. Fix the git-level issue it names (remove stale index.lock, repair repo, correct ref name)
  3. Reproduce manually: run the same git command in the stated directory
  4. Run `git fsck` if repo corruption is indicated

Example fix

// before
bd worktree remove wt-x   # exit status 128: fatal: not a git repository
// after
cd /repos/main && bd worktree remove wt-x
Defensive patterns

Strategy: try-catch

Validate before calling

git -C "$DIR" status --porcelain >/dev/null 2>&1 || { echo "git failing in $DIR"; exit 1; }

Type guard

var exitError *exec.ExitError
if errors.As(err, &exitError) {
    stderr := strings.TrimSpace(string(exitError.Stderr))
    // act on git's stderr diagnostic
}

Try / catch

out, err := gitCmd.Output()
var ee *exec.ExitError
if errors.As(err, &ee) {
    return fmt.Errorf("git failed (exit %d): %s", ee.ExitCode(), strings.TrimSpace(string(ee.Stderr)))
}

Prevention

When it happens

Trigger: Any `git` invocation in the removal pipeline exits non-zero with stderr output — e.g. `git worktree list` in a corrupt repo, invalid ref names, missing objects, locked index, or running outside a work tree.

Common situations: Corrupted .git directory; referencing a branch/ref that doesn't exist; concurrent git operations holding index.lock; running the removal from a non-repo directory.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/23f67f564dcf9842. Report an issue: GitHub.

Appendix: source

Thrown at cmd/bd/worktree_cmd.go:732

	command := exec.CommandContext(ctx, git.executable, gitArgs...)
	command.Dir = dir
	command.Env = append([]string(nil), git.env...)
	return command
}

func (git *worktreeRemovalGit) output(ctx context.Context, dir string, args ...string) ([]byte, error) {
	command := git.command(ctx, dir, args...)
	output, err := command.Output()
	if err == nil {
		return output, nil
	}

	var exitError *exec.ExitError
	if errors.As(err, &exitError) {
		stderr := strings.TrimSpace(string(exitError.Stderr))
		if stderr != "" {
			return output, fmt.Errorf("%w: %s", err, stderr)
		}
	}
	return output, err
}

func (git *worktreeRemovalGit) combinedOutput(ctx context.Context, dir string, args ...string) ([]byte, error) {
	return git.command(ctx, dir, args...).CombinedOutput()
}

type registeredWorktree struct {
	path        string
	headOID     string
	branch      string
	detached    bool
	bare        bool
	locked      bool
	lockReason  string
	prunable    bool

View on GitHub (pinned to 71377f2769)