To prevent errcheck from complaining about specific functions, use the -exclude flag with a text file containing function signatures.
Signature Formats
- Standard function:
package.FunctionName (e.g., os.ReadFile) - Value receiver method:
(package.Receiver).MethodName (e.g., (bytes.Buffer).Write) - Pointer receiver method:
(*package.Receiver).MethodName (e.g., (*bytes.Buffer).Write) - Type-specific exclusion:
package.FunctionName(TYPE) excludes the call only if the first argument is of TYPE. - Literal argument exclusion:
package.FunctionName(os.Stdout) or package.FunctionName(os.Stderr) excludes the call only when the first argument is that specific literal.
Vendored Dependencies
When using vendored dependencies, use the full import path including the vendor directory:
example.com/yourpkg/vendor/example.net/fmt2.Println
Example Exclude File
io.Copy(*bytes.Buffer)
io.Copy(os.Stdout)
os.ReadFile
// Sometimes we don't care if a HTTP request fails.
(*net/http.Client).Do
errcheck -exclude errcheck_excludes.txt path/to/package