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

Method TestErrorStack

functions_test.go:196–304  ·  view source on GitHub ↗
(c *gc.C)

Source from the content-addressed store, hash-verified

194}
195
196func (*functionSuite) TestErrorStack(c *gc.C) {
197 for i, test := range []struct {
198 message string
199 generator func(*gc.C, io.Writer) error
200 tracer bool
201 }{{
202 message: "nil",
203 generator: func(_ *gc.C, _ io.Writer) error {
204 return nil
205 },
206 }, {
207 message: "raw error",
208 generator: func(c *gc.C, expected io.Writer) error {
209 fmt.Fprint(expected, "raw")
210 return fmt.Errorf("raw")
211 },
212 }, {
213 message: "single error stack",
214 generator: func(c *gc.C, expected io.Writer) error {
215 err := errors.New("first error")
216 fmt.Fprintf(expected, "%s: first error", errorLocationValue(c))
217 return err
218 },
219 tracer: true,
220 }, {
221 message: "annotated error",
222 generator: func(c *gc.C, expected io.Writer) error {
223 err := errors.New("first error")
224 fmt.Fprintf(expected, "%s: first error\n", errorLocationValue(c))
225 err = errors.Annotate(err, "annotation")
226 fmt.Fprintf(expected, "%s: annotation", errorLocationValue(c))
227 return err
228 },
229 tracer: true,
230 }, {
231 message: "wrapped error",
232 generator: func(c *gc.C, expected io.Writer) error {
233 err := errors.New("first error")
234 fmt.Fprintf(expected, "%s: first error\n", errorLocationValue(c))
235 err = errors.Wrap(err, newError("detailed error"))
236 fmt.Fprintf(expected, "%s: detailed error", errorLocationValue(c))
237 return err
238 },
239 tracer: true,
240 }, {
241 message: "annotated wrapped error",
242 generator: func(c *gc.C, expected io.Writer) error {
243 err := errors.Errorf("first error")
244 fmt.Fprintf(expected, "%s: first error\n", errorLocationValue(c))
245 err = errors.Wrap(err, fmt.Errorf("detailed error"))
246 fmt.Fprintf(expected, "%s: detailed error\n", errorLocationValue(c))
247 err = errors.Annotatef(err, "annotated")
248 fmt.Fprintf(expected, "%s: annotated", errorLocationValue(c))
249 return err
250 },
251 tracer: true,
252 }, {
253 message: "traced, and annotated",

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
AnnotateFunction · 0.92
WrapFunction · 0.92
ErrorfFunction · 0.92
AnnotatefFunction · 0.92
TraceFunction · 0.92
MaskfFunction · 0.92
ErrorStackFunction · 0.92
errorLocationValueFunction · 0.85
newErrorFunction · 0.85
newNonComparableErrorFunction · 0.85
StackTraceMethod · 0.65

Tested by

no test coverage detected