]> Cypherpunks repositories - gostls13.git/commitdiff
errors: add errors.Unwrap example
authorjiahua wang <wjh180909@gmail.com>
Wed, 13 Oct 2021 14:16:37 +0000 (22:16 +0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 5 Nov 2021 21:28:50 +0000 (21:28 +0000)
Change-Id: Id2336a6059f7a8d627e6c0661a4d4c05485b65f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/355589
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
Trust: Robert Findley <rfindley@google.com>

src/errors/wrap_test.go

index 6f66e99c4a20cc7778bc3229697cfbf63fa747a3..a22fee2f04412e4d772ea8969f2df9c5dd033249 100644 (file)
@@ -265,3 +265,13 @@ func ExampleAs() {
        // Output:
        // Failed at path: non-existing
 }
+
+func ExampleUnwrap() {
+       err1 := errors.New("error1")
+       err2 := fmt.Errorf("error2: [%w]", err1)
+       fmt.Println(err2)
+       fmt.Println(errors.Unwrap(err2))
+       // Output
+       // error2: [error1]
+       // error1
+}