Skip to content

Commit b3d0973

Browse files
committed
add errors Match and IsAny
Simplified documentation
1 parent 0fa8635 commit b3d0973

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/errors/wrap.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,21 @@ func asType[E error](err error, ppe **E) (_ E, _ bool) {
212212
// The tree consists of err itself, followed by the errors obtained by repeatedly
213213
// calling its Unwrap() error or Unwrap() []error method. When err wraps multiple
214214
// errors, IsAny examines err followed by a depth-first traversal of its children.
215-
//
216-
// IsAny returns true if [Is](err, target) returns true for any target in targets.
217215
func IsAny(err error, targets ...error) bool {
218216
_, found := match(err, targets)
219217

220218
return found
221219
}
222220

223-
// Match returns the matched error in targets for err.
221+
// Match returns the first target error from targets that matches any error in err's tree.
224222
//
225223
// The tree consists of err itself, followed by the errors obtained by repeatedly
226224
// calling its Unwrap() error or Unwrap() []error method. When err wraps multiple
227225
// errors, Match examines err followed by a depth-first traversal of its children.
228226
//
229-
// Match returns the first target error for which [Is](err, target) returns true.
230-
// If no target matches, Match returns nil.
227+
// Match returns the first target from targets if an err is equal to that target or if
228+
// it implements a method Is(error) bool such that Is(target) returns true.
229+
// If no target matches the err, Match returns nil.
231230
func Match(err error, targets ...error) error {
232231
matched, _ := match(err, targets)
233232

0 commit comments

Comments
 (0)