From: Jonathan Amsterdam crypto/ed25519
when used with Go 1.13+.
+ Go 1.13 contains support for error wrapping, as first proposed in + the + Error Values proposal and discussed on the + associated issue. +
+
+ An error e
can wrap another error w
by providing
+ an Unwrap
method that returns w
. Both e
+ and w
are available to programs, allowing e
to provide
+ additional context to w
or to reinterpret it while still allowing
+ programs to make decisions based on w
.
+
+ To support wrapping, fmt.Errorf
now has a %w
+ verb for creating wrapped errors, and three new functions in
+ the errors
package (
+ errors.Unwrap
,
+ errors.Is
and
+ errors.As
) simplify unwrapping
+ and inspecting wrapped errors.
+
+ For more information, read the errors
package
+ documentation, or see
+ the Error Value FAQ.
+ There will soon be a blog post as well.
+
@@ -612,7 +643,8 @@ godoc
- The new function As
finds the first error in a given errorâs chain
+ The new function As
finds the first
+ error in a given errorâs chain (sequence of wrapped errors)
that matches a given targetâs type, and if so, sets the target to that error value.