crawshaw / sqlite

Go SQLite3 driver
ISC License
561 stars 67 forks source link

Detect errNoResults from sqlitex? #99

Closed shabbyrobe closed 2 years ago

shabbyrobe commented 3 years ago

I would like to be able to handle the errNoResults error in my code when using sqlitex.ResultInt64() and friends.

There's a couple of ways I can think to do it, one would be to add an assertion function like os.IsNotExist, for e.g.:

func HasNoResults(err error) bool {
    return errors.Is(err, errNoResults)
}

Or another could be to simply export ErrNoResults, to allow users of the package to call errors.Is themselves. This is less risky than it used to be, because the error implementation can change without breaking the public API now that func (m MyError) Is(target error) bool is a thing.

I would've submitted a PR already, but figured it was probably better to run it up the flagpole first to see if there's a preferred approach to surfacing errors. I'm happy to get cracking submitting something if this would be a worthwhile change.

AdamSLevy commented 2 years ago

fixed in #120