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)
| 704 | // |
| 705 | // Callers pass stderr, never runGit's combined output; see runGitSplit for why. |
| 706 | func gitFailure(op, stderr string, err error) error { |
| 707 | diag := strings.TrimSpace(stderr) |
| 708 | if diag == "" { |
| 709 | return fmt.Errorf("%s failed: %w", op, err) |
| 710 | } |
| 711 | if len(diag) > gitDiagLimit { |
| 712 | // Keep the tail: die() exits the process, so the fatal git ends on is |
| 713 | // the last thing it writes, behind any warnings that preceded it. |
| 714 | diag = diag[len(diag)-gitDiagLimit:] |
| 715 | // Cutting by bytes can land mid-rune. Git speaks the user's locale, |
| 716 | // so this is not hypothetical — #972 came from a Japanese-language |
| 717 | // Windows install. Drop the partial leading rune rather than emit |
| 718 | // invalid UTF-8. |
| 719 | for len(diag) > 0 && !utf8.RuneStart(diag[0]) { |
| 720 | diag = diag[1:] |
| 721 | } |
| 722 | diag = "..." + diag |
| 723 | } |
| 724 | return fmt.Errorf("%s failed: %w: %s", op, err, diag) |
| 725 | } |
no outgoing calls