{"record":{"id":"a1b41a927bdab75a","repo":"nikivdev/code","slug":"git-failed-a1b41a","errorCode":null,"errorMessage":"git {} failed","messagePattern":"git (.+?) failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config.rs","lineNumber":2905,"sourceCode":"        .map(|branch| branch.trim().to_string())\n        .filter(|branch| !branch.is_empty() && branch != \"HEAD\")\n}\n\nfn git_config_get(repo_root: &Path, key: &str) -> Option<String> {\n    git_capture_in(repo_root, &[\"config\", \"--get\", key])\n        .ok()\n        .map(|value| value.trim().to_string())\n        .filter(|value| !value.is_empty())\n}\n\nfn git_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {\n    let output = Command::new(\"git\")\n        .args(args)\n        .current_dir(repo_root)\n        .output()\n        .with_context(|| format!(\"failed to run git {}\", args.join(\" \")))?;\n    if !output.status.success() {\n        anyhow::bail!(\"git {} failed\", args.join(\" \"));\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).to_string())\n}\n\n/// Load config from the given path, logging a warning and returning an empty\n/// config if anything goes wrong. This keeps the daemon usable even if the\n/// config file is missing or invalid.\npub fn load_or_default<P: AsRef<Path>>(path: P) -> Config {\n    match load(path) {\n        Ok(cfg) => cfg,\n        Err(err) => {\n            tracing::warn!(\n                ?err,\n                \"failed to load flow config; starting with no managed servers\"\n            );\n            Config::default()\n        }\n    }","sourceCodeStart":2887,"sourceCodeEnd":2923,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/config.rs#L2887-L2923","documentation":"src/config.rs runs an external `git` command (with cwd = repo_root) and, if the child process exits with a non-zero status, bails with `git <args> failed`. The library throws this because the requested git operation (status, rev-parse, diff, etc.) did not succeed — e.g. the directory is not a git repository, a ref/branch doesn't exist, or the working tree has a problem git refuses to proceed on. Note the error message itself does not carry git's stderr; the underlying cause must be inspected separately.","triggerScenarios":"Any call into this config helper that shells out to `git <args>` inside repo_root where git exits non-zero: running git commands in a directory that is not a git repo, referencing a nonexistent branch/tag/commit, or git failing due to index lock, bad config, or no user identity configured for commands that need one.","commonSituations":"Reading config from a project root that was never `git init`-ed; querying a commit hash on a detached/renamed branch; a stale `.git/index.lock` left by a crashed git process; running in CI with a shallow clone where history is missing; missing gitcredentials for remote operations.","solutions":["Run the same git command manually in the repo root to see the real stderr (the anyhow message omits it).","Verify the directory is a git repository: `git -C <repo_root> rev-parse --is-inside-work-tree`.","Remove a stale `.git/index.lock` if git reports an index lock.","Confirm the referenced branch/tag/ref exists (`git branch -a`, `git tag`), or use a ref that does.","Set git identity/credentials if the command requires them (`git config user.email/user.name`)."],"exampleFix":"// before: context lost, only args shown\nanyhow::bail!(\"git {} failed\", args.join(\" \"));\n// after: include stderr for debuggability\nanyhow::bail!(\"git {} failed: {}\", args.join(\" \"), String::from_utf8_lossy(&output.stderr));","handlingStrategy":"try-catch","validationCode":"// Rust: pre-check repo before calling the config helper\nlet out = std::process::Command::new(\"git\")\n    .args([\"rev-parse\", \"--is-inside-work-tree\"])\n    .current_dir(repo_root)\n    .output()?;\nif !out.status.success() {\n    anyhow::bail!(\"{} is not a git repository\", repo_root.display());\n}","typeGuard":null,"tryCatchPattern":"match load_config_from_git(repo_root) {\n    Ok(cfg) => use(cfg),\n    Err(e) if e.to_string().starts_with(\"git \") => {\n        eprintln!(\"git failed: {e:#}. Check `git status` in {:?} and that the ref exists.\", repo_root);\n        fallback_to_default_config()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always initialize (`git init`) projects before tooling that shells out to git.","Capture and log git's stderr, not just the args, so failures are diagnosable.","Run `git fsck`/`git status` after crashes that may leave index.lock.","Pin refs/branches used by tooling and verify they exist before calling."],"tags":["git","process","external-command"],"backgroundTag":"git-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}