Skip to content

Instantly share code, notes, and snippets.

@antifuchs
Last active October 8, 2017 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antifuchs/28a02b9c025285b83c91fb35cbcad204 to your computer and use it in GitHub Desktop.
Save antifuchs/28a02b9c025285b83c91fb35cbcad204 to your computer and use it in GitHub Desktop.

What

errcheck intentionally warns on defer statements, but sadly a lot of idiomatic code uses un-checked defer calls, e.g.

	resp, err := httpClient.PostForm(ts.URL+"/login/", params)
	if err != nil {
		t.Fatal(err)
	}
	defer resp.Body.Close() // This is not a thing you should need to error-check!

So errcheck lets you exclude function definitions in its invocation, like so: errcheck -exclude go_errcheck_excludes.txtn ./ (where go_errcheck_excludes.txt is the file below).

Drawbacks

Sadly, due to errcheck#132, it doesn't support the ReadCloser's Close method, so you have to reach for the much wider Closer's Close. I think that's an OK trade-off to make, but your preferences might vary.

io/ioutil.TempFile
io/ioutil.TempDir
os.RemoveAll
(io.ReadCloser).Close
(io.Closer).Close
(*net/http/httptest.Server).Close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment