diff options
author | Jonathan Amsterdam <jba@google.com> | 2019-06-08 07:43:40 -0400 |
---|---|---|
committer | Jonathan Amsterdam <jba@google.com> | 2019-06-11 21:50:05 +0000 |
commit | f2a4c139c1e0cff35f89e4b5a531d5dedc5ed8e0 (patch) | |
tree | ce5d92ff55e44562cd76b3e4bdbae647e3e379af /src/errors | |
parent | bdd420155236768033b05524490738ca97645166 (diff) | |
download | go-f2a4c139c1e0cff35f89e4b5a531d5dedc5ed8e0.tar.gz go-f2a4c139c1e0cff35f89e4b5a531d5dedc5ed8e0.zip |
errors: clarify doc for As
Change-Id: I389d140e8fd2849e4dc438246add47819f6b25a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/181300
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/errors')
-rw-r--r-- | src/errors/wrap.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/errors/wrap.go b/src/errors/wrap.go index 760a08a4ef..666d1ff207 100644 --- a/src/errors/wrap.go +++ b/src/errors/wrap.go @@ -47,15 +47,16 @@ func Is(err, target error) bool { } } -// As finds the first error in err's chain that matches the type to which target -// points, and if so, sets the target to its value and returns true. An error -// matches a type if it is assignable to the target type, or if it has a method -// As(interface{}) bool such that As(target) returns true. As will panic if -// target is not a non-nil pointer to a type which implements error or is of -// interface type. As returns false if error is nil. +// As finds the first error in err's chain that matches target, and if so, sets +// target to that error value and returns true. // -// The As method should set the target to its value and return true if err -// matches the type to which target points. +// An error matches target if the error's concrete value is assignable to the value +// pointed to by target, or if the error has a method As(interface{}) bool such that +// As(target) returns true. In the latter case, the As method is responsible for +// setting target. +// +// As will panic if target is not a non-nil pointer to either a type that implements +// error, or to any interface type. As returns false if err is nil. func As(err error, target interface{}) bool { if target == nil { panic("errors: target cannot be nil") |