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

Method TestCause

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

Source from the content-addressed store, hash-verified

162}
163
164func (*functionSuite) TestCause(c *gc.C) {
165 c.Assert(errors.Cause(nil), gc.IsNil)
166 c.Assert(errors.Cause(someErr), gc.Equals, someErr)
167
168 fmtErr := fmt.Errorf("simple")
169 c.Assert(errors.Cause(fmtErr), gc.Equals, fmtErr)
170
171 err := errors.Wrap(someErr, fmtErr)
172 c.Assert(errors.Cause(err), gc.Equals, fmtErr)
173
174 err = errors.Annotate(err, "annotated")
175 c.Assert(errors.Cause(err), gc.Equals, fmtErr)
176
177 err = errors.Maskf(err, "masked")
178 c.Assert(errors.Cause(err), gc.Equals, err)
179
180 // Look for a file that we know isn't there.
181 dir := c.MkDir()
182 _, err = os.Stat(filepath.Join(dir, "not-there"))
183 c.Assert(os.IsNotExist(err), gc.Equals, true)
184
185 err = errors.Annotatef(err, "wrap it")
186 // Now the error itself isn't a 'IsNotExist'.
187 c.Assert(os.IsNotExist(err), gc.Equals, false)
188 // However if we use the Check method, it is.
189 c.Assert(os.IsNotExist(errors.Cause(err)), gc.Equals, true)
190}
191
192type tracer interface {
193 StackTrace() []string

Callers

nothing calls this directly

Calls 5

CauseFunction · 0.92
WrapFunction · 0.92
AnnotateFunction · 0.92
MaskfFunction · 0.92
AnnotatefFunction · 0.92

Tested by

no test coverage detected