Skip to content

Signature Of KeyValue::ReadWrite::Get #24

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

Closed
adamgfraser opened this issue Sep 23, 2023 · 3 comments · Fixed by #30
Closed

Signature Of KeyValue::ReadWrite::Get #24

adamgfraser opened this issue Sep 23, 2023 · 3 comments · Fixed by #30

Comments

@adamgfraser
Copy link

The current signature of get is:

get: func(bucket: bucket, key: key) -> result<incoming-value, error>

I would have expected the signature to be:

get: func(bucket: bucket, key: key) -> result<option<incoming-value>, error>

In the current signature, if a value does not exist this results in an error. This is somewhat subjective, but I would consider the possibility that a value does not exist for a key to be part of normal operation versus an error case (e.g. not being able to connect to the underlying data source) and would like it to be explicitly represented in the type signature.

This is especially true today because the error case is just basically a string so it is not possible for the user to introspect on the error and determine whether the value didn't exist or there was a runtime exception in a principled way. It sounds like there are plans to build out the error case and if it was an enumeration that included the value not being found then it would allow users to handle the possibility of a value not existing.

However, that still leaves implementers of the interface now in an awkward position and I tend to think that representing the optionality explicitly is the better API.

Would you consider a change for this?

@adamgfraser
Copy link
Author

Similar comment applies to get-many.

The signature could go from:

get-many: func(bucket: bucket, keys: keys) -> result<list<incoming-value>, error>

to:

get-many: func(bucket: bucket, keys: keys) -> result<list<option<incoming-value>>, error>

@Mossaka
Copy link
Collaborator

Mossaka commented Oct 16, 2023

Seems reasonable to me. @devigned what do you think?

@devigned
Copy link
Collaborator

I agree. Totally reasonable that there may not be a result due to the key not existing in the store.

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

Successfully merging a pull request may close this issue.

3 participants