Implement Error.Is() method

Author: gwdCreated May 17, 2021Updated Jul 22, 2025

Go 1.13 introduced wrapped errors, as well as errors.Is(x, y), which will automatically unwrap errors and either do a comparison, or check to see if an error's Is() method returns true. This would basically be:

go
func (err Error) Is(target Error) bool {
		switch v := target.(type) {
		case ErrNo:
			return err.Code == v
		case ErrNoExtended:
			return err.ExtendedCode == v
		}
		return false
}

Then errors.Is(err, sqlite3.ErrConstraint) should work as expected.

I can send a PR in a couple of weeks if nobody objects and/or nobody gets around to it.