diff options
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 +} |