diff options
| author | Andrew Gerrand <adg@golang.org> | 2019-05-31 20:33:01 +1000 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2019-06-03 22:09:05 +0000 |
| commit | 5e2af2b0d2e7e367e461d4162b0338ff2dc08033 (patch) | |
| tree | a0e7755e420a1f2363de1fb604398c07570b7e82 /src/errors/wrap_test.go | |
| parent | 0c75eb824ca7ca41970c2265ad1bccb82bbb408f (diff) | |
| download | go-5e2af2b0d2e7e367e461d4162b0338ff2dc08033.tar.xz | |
errors: fix package example
The example in example_test.go requires that the whole file be
displayed; the addition of ExampleAs meant that only the body of the
package example function was shown, rather than the surrounding context.
This change moves ExampleAs to the file wrap_test.go file, restoring the
package example to its former glory.
Update #31716
Change-Id: Id0ea77bc06023b239a63c1d6a7c8b3c1dae91ce9
Reviewed-on: https://go-review.googlesource.com/c/go/+/179737
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: Jean de Klerk <deklerk@google.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/errors/wrap_test.go')
| -rw-r--r-- | src/errors/wrap_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/errors/wrap_test.go b/src/errors/wrap_test.go index 2055316756..d349414527 100644 --- a/src/errors/wrap_test.go +++ b/src/errors/wrap_test.go @@ -218,3 +218,17 @@ func (errorUncomparable) Is(target error) bool { _, ok := target.(errorUncomparable) return ok } + +func ExampleAs() { + if _, err := os.Open("non-existing"); err != nil { + var pathError *os.PathError + if errors.As(err, &pathError) { + fmt.Println("Failed at path:", pathError.Path) + } else { + fmt.Println(err) + } + } + + // Output: + // Failed at path: non-existing +} |
