storm icon indicating copy to clipboard operation
storm copied to clipboard

storm.ErrNotFound vs index.ErrNotFound

Open jmalloc opened this issue 4 years ago • 0 comments

Hi, I am wondering if these two errors are supposed to be considered equivalent? I notice they are documented the same, and obviously have the same error message.

At my workplace we were just caught out by an index.ErrNotFound error in the following code:

// ListCustomers returns a slice of Customers.
func ListCustomers(ctx context.Context, tx storm.Node) ([]Customer, error) {
	var c []Customer
	err := tx.AllByIndex("Username", &c)
	if errors.Is(err, storm.ErrNotFound) { // note: errors.Is() does not match index.ErrNotFound
		return c, nil
	}
	return c, err
}

I was just hoping for some guidance as to whether I should be handling both errors explicitly.

Thanks 😄

/cc @cwx-iggy

PS: If these errors are supposed to be equivalent, but have been duplicated to avoid a cyclic package dependency, perhaps the construction via errors.New() could be moved into an internal package and referenced from both the storm and index packages?

jmalloc avatar Nov 19 '20 22:11 jmalloc