affaan-m/ECC · error · Error

failed ` : ''}

Error message

${program} ${args.join(' ')} failed${stderr ? `: ${stderr}` : ''}

What it means

runCommand is a wrapper around spawnSync used for all git/tmux invocations. When the spawned process exits with a non-zero status, it throws an Error containing the full command line and any captured stderr, so callers (and users) see exactly which external command failed and why.

Solutions

  1. Read the stderr in the error message to identify the failing git/tmux command and its cause.
  2. Clean up stale state: remove existing worktrees ('git worktree list' / 'git worktree remove') and delete leftover 'orchestrator-*' branches.
  3. Verify tmux and git are installed and on PATH, and that you are inside a git repository.
  4. Check permissions on the repo root and worktree root directories.

Example fix

// before (stale branch blocks 'git worktree add -b orchestrator-foo-worker')
git worktree add -b orchestrator-foo-worker ../foo-worktree
// after
git branch -D orchestrator-foo-worker
git worktree add -b orchestrator-foo-worker ../foo-worktree
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight checks before running the orchestrator
spawnSync('git', ['rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' });
spawnSync('tmux', ['-V'], { stdio: 'ignore' });
const wt = spawnSync('git', ['worktree', 'list'], { encoding: 'utf8' });
if (wt.stdout.includes(sessionName)) console.warn('stale worktrees exist for this session');

Try / catch

try {
  const result = runCommand('git', ['worktree', 'add', '-b', branch, path, baseRef]);
} catch (err) {
  console.error(`Command failed: ${err.message}`);
  if (err.message.includes('already exists')) {
    // clean stale worktree/branch and retry once
  }
  throw err;
}

Prevention

When it happens

Trigger: Any runCommand call whose child process exits non-zero: e.g. 'git worktree add' on a path that already exists or a branch name that already exists, 'tmux new-session'/'split-window' when no tmux server/session exists or tmux is not installed, or 'git rev-parse' in a non-git directory.

Common situations: Running the orchestrator outside a git repo; a leftover worktree or branch from a previous crashed run; tmux not installed or not running; insufficient permissions on the worktree root; git version lacking worktree support.

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 affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/9cd0a5fffaada1e0. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/tmux-worktree-orchestrator.js:336

    for (const file of artifacts.files) {
      fs.writeFileSync(file.path, file.content + '\n', 'utf8');
    }
  }
}

function runCommand(program, args, options = {}) {
  const result = spawnSync(program, args, {
    cwd: options.cwd,
    encoding: 'utf8',
    stdio: ['ignore', 'pipe', 'pipe']
  });

  if (result.error) {
    throw result.error;
  }
  if (result.status !== 0) {
    const stderr = (result.stderr || '').trim();
    throw new Error(`${program} ${args.join(' ')} failed${stderr ? `: ${stderr}` : ''}`);
  }
  return result;
}

function commandSucceeds(program, args, options = {}) {
  const result = spawnSync(program, args, {
    cwd: options.cwd,
    encoding: 'utf8',
    stdio: ['ignore', 'pipe', 'pipe']
  });
  return result.status === 0;
}

function canonicalizePath(targetPath) {
  const resolvedPath = path.resolve(targetPath);

  try {
    return fs.realpathSync.native(resolvedPath);

View on GitHub (pinned to 8321021c54)