2022-07-15 15:32:10 +02:00
|
|
|
//golangcitest:args -Eerrorlint
|
2020-10-09 15:42:48 +03:00
|
|
|
package testdata
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-05-01 18:41:26 +02:00
|
|
|
"fmt"
|
2020-10-09 15:42:48 +03:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2021-05-01 18:41:26 +02:00
|
|
|
var errLintFoo = errors.New("foo")
|
2020-10-09 15:42:48 +03:00
|
|
|
|
2021-05-01 18:41:26 +02:00
|
|
|
type errLintBar struct{}
|
2020-10-09 15:42:48 +03:00
|
|
|
|
2021-05-01 18:41:26 +02:00
|
|
|
func (*errLintBar) Error() string {
|
|
|
|
return "bar"
|
2020-10-09 15:42:48 +03:00
|
|
|
}
|
|
|
|
|
2021-05-01 18:41:26 +02:00
|
|
|
func errorLintAll() {
|
|
|
|
err := func() error { return nil }()
|
2022-08-20 18:53:45 +02:00
|
|
|
if err == errLintFoo { // want "comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error"
|
2021-05-01 18:41:26 +02:00
|
|
|
log.Println("errCompare")
|
|
|
|
}
|
2020-10-09 15:42:48 +03:00
|
|
|
|
2021-05-01 18:41:26 +02:00
|
|
|
err = errors.New("oops")
|
2022-08-20 18:53:45 +02:00
|
|
|
fmt.Errorf("error: %v", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors"
|
2020-10-09 15:42:48 +03:00
|
|
|
|
2022-08-20 18:53:45 +02:00
|
|
|
switch err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors"
|
2021-05-01 18:41:26 +02:00
|
|
|
case *errLintBar:
|
|
|
|
log.Println("errLintBar")
|
2020-10-09 15:42:48 +03:00
|
|
|
}
|
|
|
|
}
|