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

fix: storage SDK orElseThrow should take a supplier #383

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

cprice404
Copy link
Contributor

The orElseThrow signature of Java Optionals requires a single
arg, supplier, that is a lambda function returning the exception
that the user wishes to have thrown if the optional is empty.
In our current storage client code we have an empty-args signature,
which would be surprising to Java users familiar with Optionals.
This commit updates the signature to accept a supplier.

The `orElseThrow` signature of Java Optionals requires a single
arg, `supplier`, that is a lambda function returning the exception
that the user wishes to have thrown if the optional is empty.
In our current storage client code we have an empty-args signature,
which would be surprising to Java users familiar with Optionals.
This commit updates the signature to accept a supplier.
@cprice404 cprice404 requested a review from malandis July 10, 2024 21:33
@@ -64,16 +65,20 @@ public static <T> MomentoOptional<T> empty(String onEmptyExceptionMessage) {
* @return the value.
*/
public T get() {
return this.orElseThrow();
return optional.orElseThrow(() -> new ClientSdkException(onEmptyExceptionMessage));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return optional.orElseThrow(() -> new ClientSdkException(onEmptyExceptionMessage));
public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
if (this.isEmpty()) {
throw exceptionSupplier.get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cprice404 cprice404 merged commit 7f07993 into main Jul 10, 2024
5 checks passed
@cprice404 cprice404 deleted the fix-storage-or-else-throw branch July 10, 2024 21:55
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 this pull request may close these issues.

2 participants