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 errors with Is, As, or Unwrap methods implement the correct interfaces. This is not a requirement that all errors 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:
The interfaces for
errors.Is
anderrors.As
seem stable and complete. Unfortunately, it requires reading through the godoc to ensure that your custom error type correctly implementsinterface{ As(interface{}) bool }
,interface{ Is(error) bool }
, orinterface{ 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 withIs
,As
, orUnwrap
methods implement the correct interfaces. This is not a requirement that allerror
s implementIs
,As
, andUnwrap
, 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:
The text was updated successfully, but these errors were encountered: