Description
The interfaces for errors.Is
and errors.As
seem stable and complete. Unfortunately, it requires reading through the godoc to ensure that your custom error type correctly implements interface{ As(interface{}) bool }
, interface{ Is(error) bool }
, or interface{ Unwrap() error }
. This can lead to implementation bugs that fail pathologically.
Instead of exposing these symbols, as was proposed in #39539, we can add a vet check to ensure that error
s with Is
, As
, or Unwrap
methods implement the correct interfaces. This is not a requirement that all error
s implement Is
, As
, and Unwrap
, but simply that if the symbol exists, the syntax matches.
Technically, this is not required, as you can use an anonymous type to perform this check at compile time. But this is ungainly, not automatic, and fails to the same typographical issues due to its distributed implementation:
var (
_ = (interface{ As(interface{}) bool })(myError{})
_ = (interface{ Is(error) bool })(myError{})
_ = (interface{ Unwrap() error })(myError{})
_ = error(myError{})