Commit 34c91c4
contrib/scripts: fix check-fmt.sh aborting with exit 123 on Go 1.26+
gofmt was changed in Go 1.26 to exit non-zero when -d finds a diff
(https://cs.opensource.google/go/go/+/d945600d060e7a0b7c5e72ac606a017d105a17f3).
Combined with set -e and set -o pipefail at the top of the script, that
exit propagates through xargs as code 123 and kills the script before the
"Unformatted Go source code:" branch can run.
The contributor sees a cryptic "Error 123" with no diff instead of the
helpful diff output the script was designed to produce. Now that go.mod
requires Go >= 1.26, every contributor running 'make precheck' on a
freshly-bumped toolchain hits this.
Capture the gofmt output and exit code explicitly with set +e/-e around
the pipeline, then dispatch:
- non-empty diff -> exit 1 with the helpful message (existing behavior).
- empty diff but non-zero gofmt exit -> surface the real gofmt error
on stderr and propagate the exit code.
- clean tree -> exit 0.
Verified manually with Go 1.26.2 by introducing a formatting issue in a
sample file and running the script before and after the fix:
Before: exit 123, no output.
After: exit 1, prints "Unformatted Go source code:" + the diff.
A clean tree still exits 0.
Fixes: cilium#45677
Signed-off-by: Azeez Syed <syedazeez337@gmail.com>1 parent 3aa7e07 commit 34c91c4
1 file changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
14 | 21 | | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
19 | 28 | | |
20 | 29 | | |
21 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
22 | 36 | | |
0 commit comments