Showing all Go compiler errors

The Go compiler normally stops after it finds 10 errors, aborting with a too many errors message. For example:

$ go build
# sandbox/manyerrs
./errs.go:4: undefined: w
./errs.go:5: undefined: w
./errs.go:6: undefined: w
./errs.go:7: undefined: w
./errs.go:8: undefined: w
./errs.go:9: undefined: w
./errs.go:10: undefined: w
./errs.go:11: undefined: w
./errs.go:12: undefined: w
./errs.go:13: undefined: w
./errs.go:13: too many errors

This is useful default behaviour - if there's lots problems you usually don't care about seeing all of the issues. You just fix what you can see and try again.

Sometimes though you really want to see all the errors.

The trick is to use the -gcflags option to the go tool to pass -e (show all errors) to the compiler.

Here's how you do it:

$ go build -gcflags="-e"
./errs.go:4: undefined: w
./errs.go:5: undefined: w
./errs.go:6: undefined: w
./errs.go:7: undefined: w
./errs.go:8: undefined: w
./errs.go:9: undefined: w
./errs.go:10: undefined: w
./errs.go:11: undefined: w
./errs.go:12: undefined: w
./errs.go:13: undefined: w
./errs.go:14: undefined: w
./errs.go:15: undefined: w
./errs.go:16: undefined: w
./errs.go:17: undefined: w

Given that this was surprisingly difficult to find this I thought I'd write it down here. Hope this was useful.

Comments

Comments powered by Disqus