{"record":{"id":"dcbf7645da81f915","repo":"nikivdev/code","slug":"gh-is-installed-but-not-working","errorCode":null,"errorMessage":"`gh` is installed but not working","messagePattern":"`gh` is installed but not working","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":8503,"sourceCode":"}\n\nfn jj_bin() -> String {\n    env::var(\"FLOW_JJ_BIN\")\n        .ok()\n        .map(|v| v.trim().to_string())\n        .filter(|v| !v.is_empty())\n        .unwrap_or_else(|| \"jj\".to_string())\n}\n\nfn ensure_gh_available() -> Result<()> {\n    let status = Command::new(\"gh\")\n        .args([\"--version\"])\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .status()\n        .context(\"failed to run `gh` (GitHub CLI)\")?;\n    if !status.success() {\n        bail!(\"`gh` is installed but not working\");\n    }\n    Ok(())\n}\n\nfn gh_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {\n    let output = Command::new(\"gh\")\n        .current_dir(repo_root)\n        .args(args)\n        .output()\n        .with_context(|| format!(\"failed to run gh {}\", args.join(\" \")))?;\n    if !output.status.success() {\n        bail!(\n            \"gh {} failed: {}\",\n            args.join(\" \"),\n            String::from_utf8_lossy(&output.stderr).trim()\n        );\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).to_string())","sourceCodeStart":8485,"sourceCodeEnd":8521,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L8485-L8521","documentation":"The tool checks GitHub CLI availability by running `gh --version` before using gh. This error means the `gh` binary exists (it was found on PATH and could be executed) but exits non-zero even for `--version`, so it is installed but broken/unusable. The library bails rather than attempting authenticated gh API calls that would fail anyway.","triggerScenarios":"`ensure_gh()` runs `Command::new(\"gh\").arg(\"--version\")...status()` and the returned ExitStatus is not success — i.e. gh exits with an error code even on the trivial version command.","commonSituations":"Corrupted or partially upgraded gh installation; incompatible dynamic libraries on Linux; gh installed via a package manager that shipped a broken build; architecture mismatch (e.g. x86 binary on ARM).","solutions":["Reinstall gh: `brew reinstall gh` or the equivalent for your package manager","Test manually: `gh --version` should print a version and exit 0","Check `which gh` for shadowing by a broken binary earlier on PATH","If gh is not actually needed, ensure the code path that requires it is not triggered"],"exampleFix":"// before\n$ gh --version\nzsh: abort (core dumped)  gh --version\nError: `gh` is installed but not working\n// after\n$ brew reinstall gh\n$ gh --version\ngh version 2.62.0\n$ tool create-review  # proceeds","handlingStrategy":"validation","validationCode":"fn gh_works() -> bool {\n    Command::new(\"gh\")\n        .arg(\"--version\")\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .status()\n        .map(|s| s.success())\n        .unwrap_or(false)\n}\nif !gh_works() { eprintln!(\"reinstall gh before continuing\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = result {\n    if e.to_string().contains(\"installed but not working\") {\n        eprintln!(\"gh is present but broken; run `gh --version` to confirm, then reinstall\");\n    }\n    return Err(e);\n}","preventionTips":["Run `gh --version` in CI setup steps to fail fast on broken installs","Install gh from official releases rather than ad-hoc binaries","Avoid having multiple gh binaries shadowing each other on PATH","Reinstall gh after OS/library upgrades that may break its dependencies"],"tags":["github","gh-cli","installation","environment"],"backgroundTag":"gh-cli-broken-install","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}