]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.13] errors: fix wrong code in package doc
authorJonathan Amsterdam <jba@google.com>
Wed, 4 Sep 2019 17:01:16 +0000 (13:01 -0400)
committerKatie Hockman <katie@golang.org>
Wed, 4 Sep 2019 17:54:31 +0000 (17:54 +0000)
You can't call Unwrap on the return value of fmt.Errorf, but
you can pass the result to errors.Unwrap.

Also, move the description of the Unwrap function up so the
example makes sense.

Fixes #34082.

Change-Id: Ica07c44665c5e65deea4aa6a146fc543a5a0a99d
Reviewed-on: https://go-review.googlesource.com/c/go/+/193298
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>
(cherry picked from commit d9a3d902ec139c95d8dc1b69977783fb8134b552)
Reviewed-on: https://go-review.googlesource.com/c/go/+/193263
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/errors/errors.go

index 85d4260762e275ec56fd858f9bd676480f6b65eb..d923ad4b703ad59ca7381f0dfdd38e6bd70c5b0f 100644 (file)
 //
 // If e.Unwrap() returns a non-nil error w, then we say that e wraps w.
 //
+// Unwrap unpacks wrapped errors. If its argument's type has an
+// Unwrap method, it calls the method once. Otherwise, it returns nil.
+//
 // A simple way to create wrapped errors is to call fmt.Errorf and apply the %w verb
 // to the error argument:
 //
-//     fmt.Errorf("... %w ...", ..., err, ...).Unwrap()
+//     errors.Unwrap(fmt.Errorf("... %w ...", ..., err, ...))
 //
 // returns err.
 //
-// Unwrap unpacks wrapped errors. If its argument's type has an
-// Unwrap method, it calls the method once. Otherwise, it returns nil.
-//
 // Is unwraps its first argument sequentially looking for an error that matches the
 // second. It reports whether it finds a match. It should be used in preference to
 // simple equality checks: