From b402999421fbf343bfc95f38ba67fc248620b598 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Fri, 22 Apr 2016 17:40:16 +0900 Subject: [PATCH] more examples --- example_test.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/example_test.go b/example_test.go index 9995902..ea82811 100644 --- a/example_test.go +++ b/example_test.go @@ -1,13 +1,35 @@ package errors_test import ( - "errors" "fmt" + + "github.com/pkg/errors" ) func ExampleNew() { err := errors.New("whoops") - fmt.Println(err.Error()) + fmt.Println(err) // Output: whoops } + +func ExampleWrap() { + cause := errors.New("whoops") + err := errors.Wrap(cause, "oh noes") + fmt.Println(err) + + // Output: oh noes: whoops +} + +func fn() error { + return errors.Wrap(errors.Wrap(errors.Wrap(errors.New("error"), "inner"), "middle"), "outer") +} + +func ExampleCause() { + err := fn() + fmt.Println(err) + fmt.Println(errors.Cause(err)) + + // Output: outer: middle: inner: error + // error +}