Skip to content

storm.ErrNotFound vs index.ErrNotFound #281

Open
@jmalloc

Description

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions