1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//golangcitest:args -Eerrorlint
package testdata
import (
"errors"
"fmt"
"log"
)
var errLintFoo = errors.New("foo")
type errLintBar struct{}
func (*errLintBar) Error() string {
return "bar"
}
func errorLintAll() {
err := func() error { return nil }()
if err == errLintFoo { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error"
log.Println("errCompare")
}
err = errors.New("oops")
fmt.Errorf("error: %v", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
switch err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors"
case *errLintBar:
log.Println("errLintBar")
}
}
|