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)
| 796 | // |
| 797 | // Callers pass stderr, never runGit's combined output; see runGitSplit for why. |
| 798 | func gitFailure(op, stderr string, err error) error { |
| 799 | diag := strings.TrimSpace(stderr) |
| 800 | if diag == "" { |
| 801 | return fmt.Errorf("%s failed: %w", op, err) |
| 802 | } |
| 803 | if len(diag) > gitDiagLimit { |
| 804 | // Keep the tail: die() exits the process, so the fatal git ends on is |
| 805 | // the last thing it writes, behind any warnings that preceded it. |
| 806 | diag = diag[len(diag)-gitDiagLimit:] |
| 807 | // Cutting by bytes can land mid-rune. Git speaks the user's locale, |
| 808 | // so this is not hypothetical — #972 came from a Japanese-language |
| 809 | // Windows install. Drop the partial leading rune rather than emit |
| 810 | // invalid UTF-8. |
| 811 | for len(diag) > 0 && !utf8.RuneStart(diag[0]) { |
| 812 | diag = diag[1:] |
| 813 | } |
| 814 | diag = "..." + diag |
| 815 | } |
| 816 | return fmt.Errorf("%s failed: %w: %s", op, err, diag) |
| 817 | } |
no outgoing calls