nikivdev/code · error

jj root failed

Error message

jj root failed

What it means

try_jj_root runs `jj root` inside the given path to locate the jj workspace root. If the jj command runs but exits with a non-zero status (meaning the directory is not inside a jj workspace or jj itself errored), it bails with 'jj root failed'. The context 'failed to run jj root' covers the case where the process could not be spawned at all.

Source

Thrown at src/vcs.rs:76

    if !output.status.success() {
        return None;
    }
    let root = String::from_utf8_lossy(&output.stdout).trim().to_string();
    if root.is_empty() {
        None
    } else {
        Some(PathBuf::from(root))
    }
}

fn try_jj_root(path: &Path) -> Result<PathBuf> {
    let output = Command::new("jj")
        .current_dir(path)
        .arg("root")
        .output()
        .context("failed to run jj root")?;
    if !output.status.success() {
        bail!("jj root failed");
    }
    Ok(PathBuf::from(
        String::from_utf8_lossy(&output.stdout).trim(),
    ))
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Run `jj root` manually inside the target directory to see jj's actual error message (this library discards stderr).
  2. If the directory is not a jj workspace, run `jj git init --colocate` there or point the code at an existing workspace.
  3. If jj errors due to config, fix or remove ~/.config/jj/config.toml (or repo-level jj config) and retry.
  4. If the workspace was created by a newer/older jj, upgrade or downgrade jj (`jj --version`) to a compatible release and rerun.

Example fix

// before (opaque failure)
let root = try_jj_root(path).context("locate jj workspace")?;
// after (diagnose manually first)
$ cd /path/being/probed && jj root
Error: There is no jj repo in "."  ->  run `jj git init --colocate`
Defensive patterns

Strategy: try-catch

Validate before calling

use std::path::Path;
fn likely_jj_workspace(dir: &Path) -> bool {
    let mut cur = Some(dir);
    while let Some(p) = cur {
        if p.join(".jj").exists() { return true; }
        cur = p.parent();
    }
    false
}

Try / catch

match try_jj_root(path) {
    Ok(root) => println!("workspace root: {}", root.display()),
    Err(e) => {
        eprintln!("could not locate jj workspace at {}: {e}", path.display());
        eprintln!("hint: run `jj root` manually in that directory to see jj's own error");
    }
}

Prevention

When it happens

Trigger: Calling try_jj_root(path) (from ensure_jj_repo_in) where `jj root` returns a non-zero exit code: the path is not inside a jj workspace, the workspace metadata is corrupt, or the jj binary fails at runtime (bad config, incompatible workspace).

Common situations: Probing arbitrary directories that are plain git repos or not repos at all; a jj workspace whose .jj directory was partially deleted or created by an incompatible jj version; a broken jj config file (config.toml) causing jj commands to exit non-zero even outside repo detection.

Related errors


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