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