MCPcopy Create free account
hub / github.com/juju/errors / TestErrorString

Method TestErrorString

error_test.go:21–140  ·  view source on GitHub ↗

err varSomeErr

(c *gc.C)

Source from the content-addressed store, hash-verified

19var someErr = errors.New("some error") //err varSomeErr
20
21func (*errorsSuite) TestErrorString(c *gc.C) {
22 for i, test := range []struct {
23 message string
24 generator func() error
25 expected string
26 }{
27 {
28 message: "uncomparable errors",
29 generator: func() error {
30 err := errors.Annotatef(newNonComparableError("uncomparable"), "annotation")
31 return errors.Annotatef(err, "another")
32 },
33 expected: "another: annotation: uncomparable",
34 }, {
35 message: "Errorf",
36 generator: func() error {
37 return errors.Errorf("first error")
38 },
39 expected: "first error",
40 }, {
41 message: "annotated error",
42 generator: func() error {
43 err := errors.Errorf("first error")
44 return errors.Annotatef(err, "annotation")
45 },
46 expected: "annotation: first error",
47 }, {
48 message: "test annotation format",
49 generator: func() error {
50 err := errors.Errorf("first %s", "error")
51 return errors.Annotatef(err, "%s", "annotation")
52 },
53 expected: "annotation: first error",
54 }, {
55 message: "wrapped error",
56 generator: func() error {
57 err := newError("first error")
58 return errors.Wrap(err, newError("detailed error"))
59 },
60 expected: "detailed error",
61 }, {
62 message: "wrapped annotated error",
63 generator: func() error {
64 err := errors.Errorf("first error")
65 err = errors.Annotatef(err, "annotated")
66 return errors.Wrap(err, fmt.Errorf("detailed error"))
67 },
68 expected: "detailed error",
69 }, {
70 message: "annotated wrapped error",
71 generator: func() error {
72 err := errors.Errorf("first error")
73 err = errors.Wrap(err, fmt.Errorf("detailed error"))
74 return errors.Annotatef(err, "annotated")
75 },
76 expected: "annotated: detailed error",
77 }, {
78 message: "traced, and annotated",

Callers

nothing calls this directly

Calls 13

AnnotatefFunction · 0.92
ErrorfFunction · 0.92
WrapFunction · 0.92
NewFunction · 0.92
TraceFunction · 0.92
AnnotateFunction · 0.92
MaskfFunction · 0.92
UnwrapFunction · 0.92
MaskFunction · 0.92
newNonComparableErrorFunction · 0.85
newErrorFunction · 0.85
CheckMethod · 0.45

Tested by

no test coverage detected