aboutsummaryrefslogtreecommitdiff
path: root/src/errors
diff options
context:
space:
mode:
authorJean de Klerk <deklerk@google.com>2019-05-16 18:15:39 -0600
committerEmmanuel Odeke <emm.odeke@gmail.com>2019-05-17 16:21:05 +0000
commit703fb665d68ac96ae193891ffae2774c2a3deb4b (patch)
tree7bf67273afad3b95a13393c633da605a08161354 /src/errors
parentf35338582d0e0e7047fa45be3cb8064c43c50f25 (diff)
downloadgo-703fb665d68ac96ae193891ffae2774c2a3deb4b.tar.gz
go-703fb665d68ac96ae193891ffae2774c2a3deb4b.zip
errors: update As example to include else case
The current example illustrates using As when the error is able to be interpreted as an os.PathError, but elides the "else" case. This CL adds the small extra else case to make it clear that it's not safe to assume As will return true. This CL also squash the err instantiation and the err nil check into one line for brevity. Change-Id: I3d3ab483ffb38fb2788d0498b3f03229a87dd7c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/177717 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/errors')
-rw-r--r--src/errors/example_test.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/errors/example_test.go b/src/errors/example_test.go
index 7724c16cdf..d7dd782bef 100644
--- a/src/errors/example_test.go
+++ b/src/errors/example_test.go
@@ -36,11 +36,12 @@ func Example() {
}
func ExampleAs() {
- _, err := os.Open("non-existing")
- if err != nil {
+ 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)
}
}