{"record":{"id":"fe8eaebb97b3df68","repo":"nikivdev/code","slug":"jj-root-failed","errorCode":null,"errorMessage":"jj root failed","messagePattern":"jj root failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/vcs.rs","lineNumber":76,"sourceCode":"    if !output.status.success() {\n        return None;\n    }\n    let root = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    if root.is_empty() {\n        None\n    } else {\n        Some(PathBuf::from(root))\n    }\n}\n\nfn try_jj_root(path: &Path) -> Result<PathBuf> {\n    let output = Command::new(\"jj\")\n        .current_dir(path)\n        .arg(\"root\")\n        .output()\n        .context(\"failed to run jj root\")?;\n    if !output.status.success() {\n        bail!(\"jj root failed\");\n    }\n    Ok(PathBuf::from(\n        String::from_utf8_lossy(&output.stdout).trim(),\n    ))\n}\n","sourceCodeStart":58,"sourceCodeEnd":82,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/vcs.rs#L58-L82","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run `jj root` manually inside the target directory to see jj's actual error message (this library discards stderr).","If the directory is not a jj workspace, run `jj git init --colocate` there or point the code at an existing workspace.","If jj errors due to config, fix or remove ~/.config/jj/config.toml (or repo-level jj config) and retry.","If the workspace was created by a newer/older jj, upgrade or downgrade jj (`jj --version`) to a compatible release and rerun."],"exampleFix":"// before (opaque failure)\nlet root = try_jj_root(path).context(\"locate jj workspace\")?;\n// after (diagnose manually first)\n$ cd /path/being/probed && jj root\nError: There is no jj repo in \".\"  ->  run `jj git init --colocate`","handlingStrategy":"try-catch","validationCode":"use std::path::Path;\nfn likely_jj_workspace(dir: &Path) -> bool {\n    let mut cur = Some(dir);\n    while let Some(p) = cur {\n        if p.join(\".jj\").exists() { return true; }\n        cur = p.parent();\n    }\n    false\n}","typeGuard":null,"tryCatchPattern":"match try_jj_root(path) {\n    Ok(root) => println!(\"workspace root: {}\", root.display()),\n    Err(e) => {\n        eprintln!(\"could not locate jj workspace at {}: {e}\", path.display());\n        eprintln!(\"hint: run `jj root` manually in that directory to see jj's own error\");\n    }\n}","preventionTips":["Since stderr from `jj root` is discarded, run `jj root` manually in the target directory to get jj's real diagnostic","Fix jj config files (user or repo level) if jj commands fail globally","Keep jj version compatible with the workspace format (upgrade after jj version bumps)","Only probe directories you expect to be workspaces; wrap speculative probes so failure is handled, not fatal"],"tags":["vcs","jj","workspace","command-failed"],"backgroundTag":"repo-not-initialized","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}