Implement Error.Is() method
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:
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.
Seems reasonable. Perhaps we should add a case for syscall.Errno as well?
For syscall.Errno, it seems like having an Unwrap() method which would return that value if present would be better. That way any code that relied on unwrapping would work, even if it didn't know anything about sqlite3.Error. I was going to include a patch to do something like that in my series (if I got to it).
Not sure I follow. Wouldn't you want to be able to do something like errors.Is(err, syscall.ENOENT)?
I don't think implementing the Unwrap method would be straightforward, since there are three candidates that could all be considered the underlying error - err.Code, err.ExtendedCode and err.SystemErrno. Instead, we should probably implement As in a similar manner to Is.