Description
The rationale in https://go.googlesource.com/proposal/+/master/design/go2draft-error-values-overview.md mentions this:
Unwrap. It is unclear if Unwrap is the right name for the method returning the next error in the error chain. Dave Cheney’s
github.com/pkg/errors
has popularized Cause for the method name, but it also uses Cause for the function that returns the last error in the chain. At least a few people we talked to did not at first understand the subtle semantic difference between method and function. An early draft of our design used Next, but all our explanations referred to wrapping and unwrapping, so we changed the method name to match.
In summary the rationale was "some people were confused so we're going to change the name".
However this choice creates a more serious technical problem.
Suppose a program upgrades to use Go 1.13 but has some dependency library that relies on github.com/pkg/errors
(or another Cause()
-compatible error library). Now consider what happens if our program makes some API call through its dependency, and that encounters an error from the standard library -- for example io.EOF
or context.DeadlineExceeded
. And then the intermediate library dependency wraps the error using the facilities in github.com/pkg/errors
which only provides Cause()
.
How is the program now meant to identify the ultimate cause of its error?
The proposal with Is()
and Unwrap()
will be unable to "peek through" the wrappers created by the existing library code. This is defective design.
Solution: By changing the design in Go 1.13 to instead make the causer access method remain Cause()
, the new 1.13 error package would become/remain drop-in compatible with existing library error wrapper code.