nikivdev/code · error

jj {} failed

Error message

jj {} failed

What it means

jj_run_in shells out to the `jj` CLI and streams its stderr, filtering only 'Refused to snapshot' lines. If jj exits non-zero, the wrapper raises a generic 'jj <args> failed' error. The real reason is on stderr above this message in the terminal output.

Source

Thrown at src/jj.rs:3379

fn jj_run_in(repo_root: &Path, args: &[&str]) -> Result<()> {
    let output = Command::new("jj")
        .current_dir(repo_root)
        .args(args)
        .output()
        .with_context(|| format!("failed to run jj {}", args.join(" ")))?;
    let stdout = String::from_utf8_lossy(&output.stdout);
    if !stdout.trim().is_empty() {
        print!("{}", stdout);
    }
    let stderr = String::from_utf8_lossy(&output.stderr);
    for line in stderr.lines() {
        if line.contains("Refused to snapshot") {
            continue;
        }
        eprintln!("{}", line);
    }
    if !output.status.success() {
        bail!("jj {} failed", args.join(" "));
    }
    Ok(())
}

fn jj_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {
    let output = Command::new("jj")
        .current_dir(repo_root)
        .args(args)
        .output()
        .with_context(|| format!("failed to run jj {}", args.join(" ")))?;
    if !output.status.success() {
        bail!("jj {} failed", args.join(" "));
    }
    Ok(String::from_utf8_lossy(&output.stdout).to_string())
}

fn git_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {
    let output = Command::new("git")

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the stderr lines printed above the error for jj's actual message and fix that root cause.
  2. If the working copy is stale, run `jj workspace update-stale` and retry.
  3. For push rejections, `jj rebase` / `jj git fetch` then re-push; verify auth with `jj git push --bookmark <name>` directly.

Example fix

// before
jj git push --bookmark feature  # remote rejects
// after
jj git fetch
jj rebase -d main
flow push --bookmark feature
Defensive patterns

Strategy: try-catch

Validate before calling

// shell: pre-flight before push
jj workspace update-stale 2>/dev/null || true
jj bookmark list | grep -q "$BOOKMARK" || { echo "no such bookmark" >&2; exit 1; }

Try / catch

match flow_push(&opts) {
  Err(e) if e.starts_with("jj git push failed") => {
    eprintln("jj push failed — inspect stderr above; try jj git fetch + rebase, then retry");
    Err(e)
  }
  other => other,
}

Prevention

When it happens

Trigger: Any jj subcommand invoked through jj_run_in (push, edit, new, workspace ops, etc.) exits with a non-zero status — e.g. push rejected by remote, workspace not found, conflicting operation.

Common situations: Remote rejected the push (non-fast-forward, protected branch); jj version mismatch or out-of-date working copy needing `jj workspace update-stale`; network/auth failures during git push under the hood.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/fb09682a1340f67e. Report an issue: GitHub.