RSS Amplifier

menno.io · Apr 7, 2017

Showing all Go compiler errors

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

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…

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

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

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.</p>

Sometimes though you really want to see all the errors.</p>

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

Here's how you do it:</p>

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

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

Read on /posts/showing-all-go-compiler-errors/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.