github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/test/testdata/errorlint_asserts.go (about) 1 //golangcitest:args -Eerrorlint 2 //golangcitest:config_path testdata/configs/errorlint_asserts.yml 3 package testdata 4 5 import ( 6 "errors" 7 "log" 8 ) 9 10 type myError struct{} 11 12 func (*myError) Error() string { 13 return "foo" 14 } 15 16 func errorLintDoAnotherThing() error { 17 return &myError{} 18 } 19 20 func errorLintAsserts() { 21 err := errorLintDoAnotherThing() 22 var me *myError 23 if errors.As(err, &me) { 24 log.Println("myError") 25 } 26 _, ok := err.(*myError) // want "type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors" 27 if ok { 28 log.Println("myError") 29 } 30 switch err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" 31 case *myError: 32 log.Println("myError") 33 } 34 switch errorLintDoAnotherThing().(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" 35 case *myError: 36 log.Println("myError") 37 } 38 switch t := err.(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" 39 case *myError: 40 log.Println("myError", t) 41 } 42 switch t := errorLintDoAnotherThing().(type) { // want "type switch on error will fail on wrapped errors. Use errors.As to check for specific errors" 43 case *myError: 44 log.Println("myError", t) 45 } 46 }