From 546ea78efa159680dde0df42f1f2091ccafef4df Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Fri, 2 Aug 2019 06:43:20 -0400 Subject: errors: improve doc Explain wrapping and how to use Is and As in the package doc. Explain "chain" in Is and As. Updates #33364. Change-Id: Ic06362106dbd129e33dd47e63176ee5355492086 Reviewed-on: https://go-review.googlesource.com/c/go/+/188737 Reviewed-by: Rob Pike --- src/errors/wrap.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/errors/wrap.go') diff --git a/src/errors/wrap.go b/src/errors/wrap.go index 666d1ff207..240da37c29 100644 --- a/src/errors/wrap.go +++ b/src/errors/wrap.go @@ -23,6 +23,9 @@ func Unwrap(err error) error { // Is reports whether any error in err's chain matches target. // +// The chain consists of err itself followed by the sequence of errors obtained by +// repeatedly calling Unwrap. +// // An error is considered to match a target if it is equal to that target or if // it implements a method Is(error) bool such that Is(target) returns true. func Is(err, target error) bool { @@ -50,6 +53,9 @@ func Is(err, target error) bool { // 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 chain consists of err itself followed by the sequence of errors obtained by +// repeatedly calling Unwrap. +// // 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 -- cgit v1.3