{"record":{"id":"8d84ea9c11604979","repo":"alibaba/open-code-review","slug":"s-failed-w","errorCode":null,"errorMessage":"%s failed: %w","messagePattern":"(.+?) failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/diff/git.go","lineNumber":709,"sourceCode":"// gitDiagLimit bounds how much of git's stderr is quoted back in an error.\n// Git's own diagnosis is a line or two, so the ceiling is a backstop for the\n// pathological case — a flood of warnings ahead of the fatal — rather than the\n// common one.\nconst gitDiagLimit = 2000\n\n// gitFailure builds an error that carries git's own message.\n//\n// Every diff-producing caller used to drop git's output on the floor, so a\n// failure surfaced as a bare \"git show failed: exit status 129\" — true, and\n// useless. Diagnosing one then meant asking the reporter to re-run the command\n// by hand to see what git actually said (#972). The exit status alone cannot\n// distinguish an unsupported option from a bad revision or a permission error.\n//\n// Callers pass stderr, never runGit's combined output; see runGitSplit for why.\nfunc gitFailure(op, stderr string, err error) error {\n\tdiag := strings.TrimSpace(stderr)\n\tif diag == \"\" {\n\t\treturn fmt.Errorf(\"%s failed: %w\", op, err)\n\t}\n\tif len(diag) > gitDiagLimit {\n\t\t// Keep the tail: die() exits the process, so the fatal git ends on is\n\t\t// the last thing it writes, behind any warnings that preceded it.\n\t\tdiag = diag[len(diag)-gitDiagLimit:]\n\t\t// Cutting by bytes can land mid-rune. Git speaks the user's locale,\n\t\t// so this is not hypothetical — #972 came from a Japanese-language\n\t\t// Windows install. Drop the partial leading rune rather than emit\n\t\t// invalid UTF-8.\n\t\tfor len(diag) > 0 && !utf8.RuneStart(diag[0]) {\n\t\t\tdiag = diag[1:]\n\t\t}\n\t\tdiag = \"...\" + diag\n\t}\n\treturn fmt.Errorf(\"%s failed: %w: %s\", op, err, diag)\n}\n","sourceCodeStart":691,"sourceCodeEnd":726,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/diff/git.go#L691-L726","documentation":"gitFailure formats a failure from a git subprocess. When git wrote nothing to stderr, there is no diagnostic to show, so the error is simply '<op> failed: <wrapped err>'. It is the generic wrapper for runGitSplit failures across diff operations (git diff, merge-base, etc.).","triggerScenarios":"Any runGitSplit call inside GetDiff (or an anonymous helper) returning an error while stderr is empty — e.g. git killed by a signal, exec failure before git started, or git failing without writing diagnostics.","commonSituations":"git binary missing or not on PATH (exec error, no stderr from git); git terminated by OOM/signal; extremely old git version failing oddly; environment issues (broken locale, GIT_DIR misconfig) that abort silently.","solutions":["Check git is installed and on PATH (git --version) since exec failures produce empty stderr","Inspect the wrapped Go error (%w) for exit status or exec details","Re-run the same git command manually in the repo to reproduce and see output","Unset interfering GIT_* environment variables and retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"git\"); err != nil { return fmt.Errorf(\"git not on PATH: %w\", err) }","typeGuard":null,"tryCatchPattern":"d, err := differ.GetDiff(ctx, p)\nif err != nil {\n    var execErr *exec.Error\n    if errors.As(err, &execErr) { return fmt.Errorf(\"git unavailable: %w\", execErr) } // empty-stderr case\n    return err\n}","preventionTips":["Verify the git binary exists in the deployment image before running diffs","Avoid stripping environment (GIT_* variables, PATH) before subprocess calls","Log the wrapped error chain; empty stderr means the cause is in the Go-wrapped err"],"tags":["git","subprocess","error-wrapping"],"backgroundTag":"git-command-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}