]> Cypherpunks repositories - gostls13.git/commit
errors, fmt: add support for wrapping multiple errors
authorDamien Neil <dneil@google.com>
Thu, 22 Sep 2022 17:43:26 +0000 (10:43 -0700)
committerDamien Neil <dneil@google.com>
Thu, 29 Sep 2022 18:40:40 +0000 (18:40 +0000)
commit4a0a2b33dfa3c99250efa222439f2c27d6780e4a
tree25b1d2541b1b1244fe86d3b7ab690bff475e7ac7
parent36f046d934c66fb6eb47d568e04665708c096ad7
errors, fmt: add support for wrapping multiple errors

An error which implements an "Unwrap() []error" method wraps all the
non-nil errors in the returned []error.

We replace the concept of the "error chain" inspected by errors.Is
and errors.As with the "error tree". Is and As perform a pre-order,
depth-first traversal of an error's tree. As returns the first
matching result, if any.

The new errors.Join function returns an error wrapping a list of errors.

The fmt.Errorf function now supports multiple instances of the %w verb.

For #53435.

Change-Id: Ib7402e70b68e28af8f201d2b66bd8e87ccfb5283
Reviewed-on: https://go-review.googlesource.com/c/go/+/432898
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
api/next/53435.txt [new file with mode: 0644]
src/errors/errors.go
src/errors/errors_test.go
src/errors/join.go [new file with mode: 0644]
src/errors/join_test.go [new file with mode: 0644]
src/errors/wrap.go
src/errors/wrap_test.go
src/fmt/errors.go
src/fmt/errors_test.go
src/fmt/print.go