Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storm.ErrNotFound vs index.ErrNotFound #281

Open
jmalloc opened this issue Nov 19, 2020 · 0 comments
Open

storm.ErrNotFound vs index.ErrNotFound #281

jmalloc opened this issue Nov 19, 2020 · 0 comments

Comments

@jmalloc
Copy link

jmalloc commented Nov 19, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant