{"record":{"id":"455a4ea06b42d0f5","repo":"mislav/hub","slug":"error-running-git-version-s","errorCode":null,"errorMessage":"error running git version: %s","messagePattern":"error running git version: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"git/git.go","lineNumber":18,"sourceCode":"package git\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/github/hub/v2/cmd\"\n)\n\nvar GlobalFlags []string\n\nfunc Version() (string, error) {\n\tversionCmd := gitCmd(\"version\")\n\toutput, err := versionCmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error running git version: %s\", err)\n\t}\n\treturn firstLine(output), nil\n}\n\nvar cachedDir string\n\nfunc Dir() (string, error) {\n\tif cachedDir != \"\" {\n\t\treturn cachedDir, nil\n\t}\n\n\tdirCmd := gitCmd(\"rev-parse\", \"-q\", \"--git-dir\")\n\tdirCmd.Stderr = nil\n\toutput, err := dirCmd.Output()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Not a git repository (or any of the parent directories): .git\")\n\t}\n","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/git/git.go#L1-L36","documentation":"Version() runs `git version` via exec.Command().Output() and wraps any failure of the git binary invocation into this error. It means the library could not execute git (or git exited non-zero), so it cannot report the git version string. This is an environment/toolchain problem, not a code problem.","triggerScenarios":"Calling git.Version() when the git binary is not installed, not on PATH, not executable, or otherwise fails to run `git version` (e.g. corrupted install, exec format issue).","commonSituations":"Fresh containers/CI images without git installed; PATH not set up in the process environment; restricted environments where spawning processes is blocked; broken git installation.","solutions":["Install git or add it to PATH (e.g. apt-get install git / ensure /usr/bin/git exists)","Verify manually with `git version` in the same environment the tool runs in","Check the PATH of the process (systemd services/CI often have a minimal PATH)","Inspect the wrapped %s error for the underlying exec detail"],"exampleFix":"// before: assume git exists\nversion, _ := git.Version()\n// after: check availability first\nif _, err := exec.LookPath(\"git\"); err != nil {\n    return fmt.Errorf(\"git is not installed or not in PATH: %w\", err)\n}\nversion, err := git.Version()\nif err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"git\"); err != nil {\n    return fmt.Errorf(\"git binary required but not found in PATH\")\n}","typeGuard":null,"tryCatchPattern":"version, err := git.Version()\nif err != nil {\n    return fmt.Errorf(\"git unavailable: %w\", err)\n}","preventionTips":["Ensure git is installed in every deployment image/CI job","Pin git in Dockerfiles and CI setup steps","Check exec.LookPath(\"git\") at tool startup and fail fast with a clear message","Beware minimal PATHs under systemd/cron — set PATH explicitly"],"tags":["git","exec","environment","path"],"backgroundTag":"git-binary-not-found","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}