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

Remove special "KeyError" and return undefined from stores for missing key #10

Closed
manzt opened this issue Dec 9, 2020 · 2 comments
Closed

Comments

@manzt
Copy link
Owner

manzt commented Dec 9, 2020

Adapted from: gzuidhof/zarr.js#69

A KeyError is a built in python error that's thrown when a key is missing from a MutableMapping. In JavaScript, the equivalent behavior is to just return undefined when a key is missing. Making this change would remove a lot of the try/catch blocks from the core implementation and instead we would just call:

// Store returns 'undefined' instead of throwing custom error if chunk is missing.
// Otherwise the store can throw any other error and it will propagate up.
const chunk = await this.store.get(ckey);
if (!chunk) {
  /* create the missing chunk */ 
} else {
  /* decode the chunk */
}
@manzt
Copy link
Owner Author

manzt commented Dec 9, 2020

This means that custom store implementations don't need to have zarrita as a dependency, and instead can explicitly return undefined when a key is missing.

@manzt
Copy link
Owner Author

manzt commented Dec 11, 2020

After experimenting with this for a bit, I'm not sure what the "right" approach is here. We would need to be careful in handling the store internally (and this could bite us), but custom store implementations would be much more simple:

1.) return bytes if key in store.
2.) return undefined if not in store.

@manzt manzt mentioned this issue Dec 15, 2020
@manzt manzt closed this as completed Jul 30, 2021
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