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>
package errors_test
import (
- "errors"
"fmt"
- "os"
"time"
)
}
// Output: 1989-03-15 22:30:00 +0000 UTC: the file system has gone away
}
-
-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
-}
_, 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
+}