Commit f2a4c139 authored by Jonathan Amsterdam's avatar Jonathan Amsterdam

errors: clarify doc for As

Change-Id: I389d140e8fd2849e4dc438246add47819f6b25a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/181300Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent bdd42015
...@@ -47,15 +47,16 @@ func Is(err, target error) bool { ...@@ -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 // As finds the first error in err's chain that matches target, and if so, sets
// points, and if so, sets the target to its value and returns true. An error // target to that error value and returns true.
// 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.
// //
// The As method should set the target to its value and return true if err // An error matches target if the error's concrete value is assignable to the value
// matches the type to which target points. // 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 { func As(err error, target interface{}) bool {
if target == nil { if target == nil {
panic("errors: target cannot be nil") panic("errors: target cannot be nil")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment