gitFailure builds an error that carries git's own message. Every diff-producing caller used to drop git's output on the floor, so a failure surfaced as a bare "git show failed: exit status 129" — true, and useless. Diagnosing one then meant asking the reporter to re-run the command by hand to see w
(op, stderr string, err error)
| 802 | // |
| 803 | // Callers pass stderr, never runGit's combined output; see runGitSplit for why. |
| 804 | func gitFailure(op, stderr string, err error) error { |
| 805 | diag := strings.TrimSpace(stderr) |
| 806 | if diag == "" { |
| 807 | return fmt.Errorf("%s failed: %w", op, err) |
| 808 | } |
| 809 | if len(diag) > gitDiagLimit { |
| 810 | // Keep the tail: die() exits the process, so the fatal git ends on is |
| 811 | // the last thing it writes, behind any warnings that preceded it. |
| 812 | diag = diag[len(diag)-gitDiagLimit:] |
| 813 | // Cutting by bytes can land mid-rune. Git speaks the user's locale, |
| 814 | // so this is not hypothetical — #972 came from a Japanese-language |
| 815 | // Windows install. Drop the partial leading rune rather than emit |
| 816 | // invalid UTF-8. |
| 817 | for len(diag) > 0 && !utf8.RuneStart(diag[0]) { |
| 818 | diag = diag[1:] |
| 819 | } |
| 820 | diag = "..." + diag |
| 821 | } |
| 822 | return fmt.Errorf("%s failed: %w: %s", op, err, diag) |
| 823 | } |
no outgoing calls