Introspect multierrors with errors.Is and errors.As
mainThe multierror.Error type is compatible with the standard library errors package. You can use errors.Is to check for specific error values and errors.As to extract specific error types from the collection.
Check for an exact error value:
err := somefunc()
if errors.Is(err, os.ErrNotExist) {
// err contains os.ErrNotExist
}Extract a specific error type:
var errRich RichErrorType
if errors.As(err, &errRich) {
// It has it, and now errRich is populated.
}// Assume err is a multierror value
err := somefunc()
// We want to know if "err" has a "RichErrorType" in it and extract it.
var errRich RichErrorType
if errors.As(err, &errRich) {
// It has it, and now errRich is populated.
}