What is the difference between errors.Is and errors.As, and how do they help when working with wrapped errors?
Last updated
errors.Is(err, target)checks whether the error chain contains a specific sentinel value, e.g.sql.ErrNoRows.errors.As(err, &target)finds the first error of a given type in the chain and assigns it to your pointer, so you can read its fields.Both walk the chain via
Unwrap(), which matters because wrapping with%wchanges the outer value and breaks plain==comparison.