Debian Codegraph @

go/analysis/passes/printf/testdata/src/w/w.go

raw symbols SCIP
1 package w
2
3 import (
4 "fmt"
5 "log"
6 )
7
8 type CustomError struct {
9 Msg string
10 }
11
12 func (e CustomError) Error() string {
13 return e.Msg
14 }
15
16 type E int
17
18 func (*E) Error() string {
19 return ""
20 }
21
22 func PrintfTests() {
23 fmt.Errorf("%w", &CustomError{Msg: "custom error"}) // want `%w wants operand of error type CustomError, not pointer type \*CustomError \(defeats errors.Is\)`
24 fmt.Errorf("%w", CustomError{Msg: "custom error"})
25 var err *CustomError
26 fmt.Errorf("%w", err) // want `%w wants operand of error type CustomError, not pointer type \*CustomError \(defeats errors.Is\)`
27
28 var e *E
29 fmt.Errorf("%w", e) // nope - Error method is attached to the pointer type *E
30
31 log.Printf("%w", &CustomError{Msg: "custom error"}) // want `log.Printf does not support error-wrapping directive %w`
32 }