{"record":{"id":"d175cb689ad28807","repo":"helix-editor/helix","slug":"git-command-failed-stdout-stderr","errorCode":null,"errorMessage":"Git command failed.\nStdout: {}\nStderr: {}","messagePattern":"Git command failed\\.\nStdout: (.+?)\nStderr: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-loader/src/grammar.rs","lineNumber":489,"sourceCode":"// A wrapper around 'git' commands which returns stdout in success and a\n// helpful error message showing the command, stdout, and stderr in error.\nfn git<I, S>(repository_dir: &Path, args: I) -> Result<String>\nwhere\n    I: IntoIterator<Item = S>,\n    S: AsRef<std::ffi::OsStr>,\n{\n    let output = Command::new(\"git\")\n        .args(args)\n        .current_dir(repository_dir)\n        .output()?;\n\n    if output.status.success() {\n        Ok(String::from_utf8_lossy(&output.stdout)\n            .trim_end()\n            .to_owned())\n    } else {\n        // TODO: figure out how to display the git command using `args`\n        Err(anyhow!(\n            \"Git command failed.\\nStdout: {}\\nStderr: {}\",\n            String::from_utf8_lossy(&output.stdout),\n            String::from_utf8_lossy(&output.stderr),\n        ))\n    }\n}\n\nenum BuildStatus {\n    AlreadyBuilt,\n    Built,\n}\n\nfn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<BuildStatus> {\n    let grammar_dir = if let GrammarSource::Local { path } = &grammar.source {\n        PathBuf::from(&path)\n    } else {\n        crate::runtime_dirs()\n            .first()","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-loader/src/grammar.rs#L471-L507","documentation":"Raised by helix-loader's grammar fetch helper when a 'git' invocation inside the grammar sources directory exits non-zero; stdout and stderr of git are embedded verbatim. This is the generic wrapper for every git failure during 'hx --grammar fetch' (clone, fetch, checkout of pinned revisions).","triggerScenarios":"Running 'hx --grammar fetch' (or first use triggering fetch) while offline, behind a misconfigured proxy, with an unreachable/censored git host, when a pinned revision no longer exists upstream, or when git itself errors (bad object database, unsafe repository ownership 'detected dubious ownership').","commonSituations":"Corporate proxy/MITM TLS rejecting github.com; a grammar repo force-pushed and the pinned commit vanished; git safe.directory refusing a cache dir written by another user; GitHub rate limiting or DNS failure. Note git's HTTP errors often appear only in the embedded stderr.","solutions":["Read the embedded Stderr first - it names the actual git failure (network, TLS, 'dubious ownership', missing ref)","For dubious ownership: git config --global --add safe.directory <grammar sources dir shown in the error>","For network issues: fix proxy/DNS or retry when online; run the same git command manually in the reported sources directory to reproduce","If the pinned revision is gone: update Helix (revised pins) or override the grammar source in languages.toml to a branch/tag that exists"],"exampleFix":"# before: hx --grammar fetch fails with 'fatal: unable to access ...':\n# after: configure proxy then retry\ngit config --global http.proxy http://proxy.example.com:8080\nhx --grammar fetch","handlingStrategy":"retry","validationCode":"// Pre-flight: is git available and is the host reachable?\nfn fetch_preconditions_ok() -> bool {\n    std::process::Command::new(\"git\").arg(\"--version\").output().is_ok_and(|o| o.status.success())\n}","typeGuard":null,"tryCatchPattern":"// Grammar fetch is a Result-returning function; retry transient network\n// failures a couple of times, fail fast on permanent ones:\nlet mut attempt = 0;\nloop {\n    match helix_loader::grammar::fetch_grammars() {\n        Ok(()) => break,\n        Err(e) if attempt < 2 && e.to_string().contains(\"Connection\") => { attempt += 1; continue; }\n        Err(e) => { eprintln!(\"grammar fetch failed: {e}\"); std::process::exit(1); }\n    }\n}","preventionTips":["Run 'hx --grammar fetch' on a networked machine and vendor runtime/grammars for offline builds","Add safe.directory entries for shared/CI grammar caches","Pin via updated Helix releases so grammar revisions exist upstream","Read embedded stderr before changing anything - it names the real git error"],"tags":["rust","helix","grammar","tree-sitter","git","network"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}