Golang linter to check the errors handling expressions
Starting from Go 1.13 the standard error type behaviour was changed: one error could be derived from another with fmt.Errorf() method using %w format specifier.
So the errors hierarchy could be built for flexible and responsible errors processing.
And to make this possible at least two simple rules should be followed:
-
errorvalues should not be compared directly but witherrors.Is()method. -
errorshould not be created dynamically from scratch but by the wrapping the static (package-level) error.
This linter is checking the code for these 2 rules compliance.
So, err113 reports every == and != comparison for exact error type variables except comparison to nil and io.EOF.
Also, any call of errors.New() and fmt.Errorf() methods are reported except the calls used to initialise package-level variables and the fmt.Errorf() calls wrapping the other errors.
Note: non-standard packages, like github.com/pkg/errors are ignored completely.
Defined by singlechecker package.
err113: checks the error handling rules according to the Go 1.13 new error type
Usage: err113 [-flag] [package]
Flags:
-V print version and exit
-all
no effect (deprecated)
-c int
display offending line with this many lines of context (default -1)
-cpuprofile string
write CPU profile to this file
-debug string
debug flags, any subset of "fpstv"
-fix
apply all suggested fixes
-flags
print analyzer flags in JSON
-json
emit JSON output
-memprofile string
write memory profile to this file
-source
no effect (deprecated)
-tags string
no effect (deprecated)
-trace string
write trace log to this file
-v no effect (deprecated)To Iskander (Alex) Sharipov for the really useful advice.
To Jack Whelpton for the bugfix provided.