Commit d9a3d902 authored by Jonathan Amsterdam's avatar Jonathan Amsterdam

errors: fix wrong code in package doc

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 #34061.

Change-Id: Ica07c44665c5e65deea4aa6a146fc543a5a0a99d
Reviewed-on: https://go-review.googlesource.com/c/go/+/193298
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: default avatarKatie Hockman <katie@golang.org>
parent 6fcc2d85
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
// //
// If e.Unwrap() returns a non-nil error w, then we say that e wraps w. // 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 // A simple way to create wrapped errors is to call fmt.Errorf and apply the %w verb
// to the error argument: // to the error argument:
// //
// fmt.Errorf("... %w ...", ..., err, ...).Unwrap() // errors.Unwrap(fmt.Errorf("... %w ...", ..., err, ...))
// //
// returns 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 // 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 // second. It reports whether it finds a match. It should be used in preference to
// simple equality checks: // simple equality checks:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment