| 162 | } |
| 163 | |
| 164 | func (*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 | |
| 192 | type tracer interface { |
| 193 | StackTrace() []string |