Пример #1
0
func (*functionSuite) TestWrapOfNil(c *gc.C) {
	detailed := errors.New("detailed")
	err := errors.Wrap(nil, detailed) //err nilWrapTest
	c.Assert(err.Error(), gc.Equals, "detailed")
	c.Assert(errors.Cause(err), gc.Equals, detailed)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["nilWrapTest"].String())
}
Пример #2
0
func checkErr(c *gc.C, err, cause error, msg string, details string) {
	c.Assert(err, gc.NotNil)
	c.Assert(err.Error(), gc.Equals, msg)
	c.Assert(errors.Cause(err), gc.Equals, cause)
	expectedDetails := replaceLocations(details)
	c.Assert(errors.Details(err), gc.Equals, expectedDetails)
}
Пример #3
0
func (*functionSuite) TestCause(c *gc.C) {
	c.Assert(errors.Cause(nil), gc.IsNil)
	c.Assert(errors.Cause(someErr), gc.Equals, someErr)

	fmtErr := fmt.Errorf("simple")
	c.Assert(errors.Cause(fmtErr), gc.Equals, fmtErr)

	err := errors.Wrap(someErr, fmtErr)
	c.Assert(errors.Cause(err), gc.Equals, fmtErr)

	err = errors.Annotate(err, "annotated")
	c.Assert(errors.Cause(err), gc.Equals, fmtErr)

	err = errors.Maskf(err, "maksed")
	c.Assert(errors.Cause(err), gc.Equals, err)

	// Look for a file that we know isn't there.
	dir := c.MkDir()
	_, err = os.Stat(filepath.Join(dir, "not-there"))
	c.Assert(os.IsNotExist(err), jc.IsTrue)

	err = errors.Annotatef(err, "wrap it")
	// Now the error itself isn't a 'IsNotExist'.
	c.Assert(os.IsNotExist(err), jc.IsFalse)
	// However if we use the Check method, it is.
	c.Assert(os.IsNotExist(errors.Cause(err)), jc.IsTrue)
}
Пример #4
0
func (*functionSuite) TestWrap(c *gc.C) {
	first := errors.New("first") //err wrapFirst
	detailed := errors.New("detailed")
	err := errors.Wrap(first, detailed) //err wrapTest
	c.Assert(err.Error(), gc.Equals, "detailed")
	c.Assert(errors.Cause(err), gc.Equals, detailed)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["wrapFirst"].String())
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["wrapTest"].String())
}
Пример #5
0
func (*functionSuite) TestAnnotatef(c *gc.C) {
	first := errors.New("first")
	err := errors.Annotatef(first, "annotation %d", 2) //err annotatefTest
	c.Assert(err.Error(), gc.Equals, "annotation 2: first")
	c.Assert(errors.Cause(err), gc.Equals, first)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["annotatefTest"].String())

	c.Assert(errors.Annotatef(nil, "annotate"), gc.IsNil)
}
Пример #6
0
func (*functionSuite) TestTrace(c *gc.C) {
	first := errors.New("first")
	err := errors.Trace(first) //err traceTest
	c.Assert(err.Error(), gc.Equals, "first")
	c.Assert(errors.Cause(err), gc.Equals, first)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["traceTest"].String())

	c.Assert(errors.Trace(nil), gc.IsNil)
}
Пример #7
0
func (*functionSuite) TestMaskf(c *gc.C) {
	first := errors.New("first")
	err := errors.Maskf(first, "masked %d", 42) //err maskfTest
	c.Assert(err.Error(), gc.Equals, "masked 42: first")
	c.Assert(errors.Cause(err), gc.Equals, err)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["maskfTest"].String())

	c.Assert(errors.Maskf(nil, "mask"), gc.IsNil)
}
Пример #8
0
func (*errorsSuite) TestNewErr(c *gc.C) {
	if runtime.Compiler == "gccgo" {
		c.Skip("gccgo can't determine the location")
	}
	err := newEmbed("testing %d", 42) //err embedErr
	c.Assert(err.Error(), gc.Equals, "testing 42")
	c.Assert(errors.Cause(err), gc.Equals, err)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["embedErr"].String())
}
Пример #9
0
func (*functionSuite) TestDeferredAnnotatef(c *gc.C) {
	// NOTE: this test fails with gccgo
	if runtime.Compiler == "gccgo" {
		c.Skip("gccgo can't determine the location")
	}
	first := errors.New("first")
	test := func() (err error) {
		defer errors.DeferredAnnotatef(&err, "deferred %s", "annotate")
		return first
	} //err deferredAnnotate
	err := test()
	c.Assert(err.Error(), gc.Equals, "deferred annotate: first")
	c.Assert(errors.Cause(err), gc.Equals, first)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["deferredAnnotate"].String())

	err = nil
	errors.DeferredAnnotatef(&err, "deferred %s", "annotate")
	c.Assert(err, gc.IsNil)
}
Пример #10
0
func (*functionSuite) TestErrorf(c *gc.C) {
	err := errors.Errorf("testing %d", 42) //err errorfTest
	c.Assert(err.Error(), gc.Equals, "testing 42")
	c.Assert(errors.Cause(err), gc.Equals, err)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["errorfTest"].String())
}
Пример #11
0
func (*functionSuite) TestNew(c *gc.C) {
	err := errors.New("testing") //err newTest
	c.Assert(err.Error(), gc.Equals, "testing")
	c.Assert(errors.Cause(err), gc.Equals, err)
	c.Assert(errors.Details(err), jc.Contains, tagToLocation["newTest"].String())
}