aboutsummaryrefslogtreecommitdiff
path: root/src/errors/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors/example_test.go')
-rw-r--r--src/errors/example_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/errors/example_test.go b/src/errors/example_test.go
index 278df8c7da..92ef36b101 100644
--- a/src/errors/example_test.go
+++ b/src/errors/example_test.go
@@ -102,6 +102,18 @@ func ExampleAs() {
// Failed at path: non-existing
}
+func ExampleAsType() {
+ if _, err := os.Open("non-existing"); err != nil {
+ if pathError, ok := errors.AsType[*fs.PathError](err); ok {
+ fmt.Println("Failed at path:", pathError.Path)
+ } else {
+ fmt.Println(err)
+ }
+ }
+ // Output:
+ // Failed at path: non-existing
+}
+
func ExampleUnwrap() {
err1 := errors.New("error1")
err2 := fmt.Errorf("error2: [%w]", err1)