{"record":{"id":"65ab922dd1cda2bb","repo":"alibaba/open-code-review","slug":"w-s-65ab92","errorCode":null,"errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/gitcmd/runner.go","lineNumber":125,"sourceCode":"\t\treturn err\n\t}\n\n\tif err := cmd.Start(); err != nil {\n\t\treturn err\n\t}\n\n\tconsumeErr := consume(stdoutPipe)\n\tif consumeErr != nil {\n\t\tcmd.Process.Kill()\n\t}\n\twaitErr := cmd.Wait()\n\n\tif consumeErr != nil {\n\t\treturn consumeErr\n\t}\n\tif waitErr != nil {\n\t\tif stderrBuf.Len() > 0 {\n\t\t\treturn fmt.Errorf(\"%w: %s\", waitErr, stderrBuf.String())\n\t\t}\n\t\treturn waitErr\n\t}\n\treturn nil\n}\n","sourceCodeStart":107,"sourceCodeEnd":131,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/gitcmd/runner.go#L107-L131","documentation":"Stream (internal/gitcmd/runner.go:125) runs a git command, streams its stdout to a consume callback, and captures stderr in parallel. When the git process exits non-zero (waitErr) and something was written to stderr, it wraps the exit error with the stderr text via fmt.Errorf(\"%w: %s\", ...). The wrap preserves the original *exec.ExitError for errors.Is/As inspection while surfacing git's own diagnostic message.","triggerScenarios":"Any Stream call (e.g. readLinesFromGitShow passing `git show <rev>`) where the git process exits non-zero after writing to stderr: bad revision, corrupt object, missing file at that rev, or the context being cancelled mid-run leaving partial stderr output.","commonSituations":"Requesting a commit hash that does not exist locally (shallow clone or after a force-push rewrote history); reading `git show` output in a repo whose objects were pruned; running in a directory that is not a git work tree (git prints 'fatal: not a git repository' to stderr).","solutions":["Read the appended stderr text — it is git's own message and names the failing revision or cause","Verify the commit/blob identifier exists: git cat-file -e <rev> before calling Stream","Run git fetch (or unshallow) if the revision may exist only on the remote","Confirm repoDir passed to Stream is a valid git work tree"],"exampleFix":"// before\ncount, err := readLinesFromGitShow(ctx, repo, unknownHash)\n// after\nif err := repo.VerifyCommit(ctx, unknownHash); err != nil {\n    return fmt.Errorf(\"commit %s not present locally, run git fetch: %w\", unknownHash, err)\n}\ncount, err := readLinesFromGitShow(ctx, repo, unknownHash)","handlingStrategy":"try-catch","validationCode":"if err := exec.CommandContext(ctx, \"git\", \"-C\", repoDir, \"cat-file\", \"-e\", rev+\"^{commit}\").Run(); err != nil {\n    return fmt.Errorf(\"revision %s not present in %s: run git fetch\", rev, repoDir)\n}","typeGuard":"var exitErr *exec.ExitError\nif errors.As(err, &exitErr) {\n    // git-specific failure; exitErr.ExitCode() tells which\n}","tryCatchPattern":"if err := runner.Stream(ctx, repoDir, consume, \"show\", rev); err != nil {\n    var exitErr *exec.ExitError\n    if errors.As(err, &exitErr) {\n        log.Printf(\"git exited %d for %s: %v\", exitErr.ExitCode(), rev, err)\n    }\n    return err\n}","preventionTips":["Pre-check revisions with git cat-file -e before streaming","Ensure repoDir is a git work tree before invoking Stream","Fetch regularly in shallow/CI clones so referenced revisions exist","Always fully drain the stdout reader in consume to avoid broken-pipe waits"],"tags":["git","process-exit","stderr","exec"],"backgroundTag":"git-command-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}