Closed malandis closed 2 months ago
Leaving this as draft for not but open for design/ergonomics review.
@kvcache we spent some time discussing / playing around with ideas based on your feedback (thank you) and decided to stick with the possibility of adding the "throw-y" versions in the future. We did change the happy-path code route to expose valueWhenFound
to give access to the value directly, rather than having to go through the found()
chain. This sheds one level of accessor calls and puts us pretty much on par with SDKs like dynamo (though with more null safety).
We are going to go ahead and merge and release these changes so we'll at least be closer to the finish line if some users start testing this week.
If you have a better idea for that name, or other things you still feel strongly about, let us know. We would have preferred to call that just value()
but the return type collides with the one from GetResponse.Found.value()
so this was what we came up with.
GetResponse.Success
intoGetResponse.Found
and, in the event the item isn't found,GetResponse.NotFound
. This sheds the optional onvalue
.valueWhenFound
shortcut accessor on the interface that returns aMomentoOptional<StorageValue>
.Throw exceptions whenReturn aStorageValue::get*
are called on the wrong type. This sheds theOptional
on those responses.MomentoOptional
which allows for both optional behavior and custom error messages. A careful user can still switch onStorageValue::getType
for exhaustiveness checks.AddWill add this on demand per user feedback in order to keep the API slim.GetResponse::asFound
which returnsGetResponseFound
in the event of aGetResponse.Found
otherwise throws an exception.MomentoOptional
for the convenience of a parameter-lessorElseThrow
method. TheorElseThrow
method will throw aClientSdkException
when the optional is empty with an informative error message. This makes usingGetResponse::found
slightly less long winded.