{"record":{"id":"c75ec472a2fd7645","repo":"nikivdev/code","slug":"jj-log-failed-in","errorCode":null,"errorMessage":"jj log failed in {}","messagePattern":"jj log failed in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pr_preview.rs","lineNumber":1440,"sourceCode":"            )\n        })?;\n    if !repo_root.join(\".git\").exists() {\n        bail!(\n            \"derived shared repo root {} does not contain .git\",\n            repo_root.display()\n        );\n    }\n    Ok(repo_root)\n}\n\nfn detect_jj_head_ref(workspace_root: &Path) -> Result<String> {\n    let output = Command::new(\"jj\")\n        .current_dir(workspace_root)\n        .args([\"log\", \"-r\", \"@ | @-\", \"--no-graph\", \"-T\", \"bookmarks\"])\n        .output()\n        .with_context(|| format!(\"failed to run jj log in {}\", workspace_root.display()))?;\n    if !output.status.success() {\n        bail!(\"jj log failed in {}\", workspace_root.display());\n    }\n    let mut bookmarks = parse_jj_bookmark_tokens(&String::from_utf8_lossy(&output.stdout));\n    bookmarks.sort();\n    bookmarks.dedup();\n    if let Some(leaf) = bookmarks\n        .iter()\n        .find(|token| token.starts_with(\"review/\") || token.starts_with(\"codex/\"))\n    {\n        return Ok(leaf.clone());\n    }\n    if let Some(stable) = bookmarks\n        .iter()\n        .find(|token| !token.starts_with(\"recovery/\") && !token.starts_with(\"backup/\"))\n    {\n        return Ok(stable.clone());\n    }\n    bookmarks.into_iter().next().ok_or_else(|| {\n        anyhow::anyhow!(","sourceCodeStart":1422,"sourceCodeEnd":1458,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/pr_preview.rs#L1422-L1458","documentation":"This error is raised when the `jj log -r '@ | @-' --no-graph -T bookmarks` command exits with a non-zero status while collecting jj bookmark names for a PR preview. It means jj itself ran (it was found on PATH and started) but reported failure, e.g. because the directory is not a jj workspace, the working copy is corrupt, or the repo uses a different VCS. The library bails out rather than silently treating the preview as having no bookmarks.","triggerScenarios":"Calling the PR preview code path in a directory that is not a jj workspace (`jj log` exits with 'not a workspace'), a corrupted or locked jj working copy (.jj directory missing or stale), or a jj version/config that rejects the `-T bookmarks` template or the `@ | @-` revision set.","commonSituations":"Running the tool inside a plain git repository (no .jj), running it in a subdirectory outside the workspace root, a jj upgrade that changed template syntax, or a leftover partial jj workspace after an interrupted operation.","solutions":["Run `jj log -r '@ | @-' --no-graph -T bookmarks` manually in the reported directory to see jj's real error message.","If the directory is meant to be a git repo, initialize or colocate jj with `jj git init --colocate` (or skip the jj path if the project uses git).","Run `jj workspace update-stale` or `jj workspace root` checks if the working copy is stale; re-clone or re-init if .jj is corrupt.","Verify your jj version supports the flags used and upgrade/downgrade jj accordingly."],"exampleFix":"// before\nbail!(\"jj log failed in {}\", workspace_root.display());\n// after\nlet has_jj = workspace_root.join(\".jj\").exists();\nif !output.status.success() {\n    if !has_jj {\n        return Ok(Vec::new()); // gracefully degrade: not a jj workspace\n    }\n    bail!(\"jj log failed in {}: {}\", workspace_root.display(),\n        String::from_utf8_lossy(&output.stderr));\n}","handlingStrategy":"fallback","validationCode":"let is_jj_ws = workspace_root.join(\".jj\").exists();\nif !is_jj_ws {\n    // skip jj bookmark collection, use git fallback\n}","typeGuard":null,"tryCatchPattern":"// handle the anyhow error and degrade gracefully\nmatch collect_jj_bookmarks(workspace_root) {\n    Ok(b) => b,\n    Err(_) => Vec::new(), // treat as no jj bookmarks\n}","preventionTips":["Check for .jj directory before invoking jj commands.","Pin/test the jj version your tooling relies on.","Run jj commands against the workspace root, not subdirectories."],"tags":["cli","version-control","subprocess","jj"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}