Skip to content

Commit eaf7afe

Browse files
Michael Rosenbergcjpatton
authored andcommitted
Cleanup get_maybe
1 parent 988af54 commit eaf7afe

File tree

1 file changed

+5
-11
lines changed
  • crates/generic_log_worker/src

1 file changed

+5
-11
lines changed

crates/generic_log_worker/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,12 @@ pub fn get_durable_object_stub(
148148
/// Gets the value from the given DO storage backend with the given key. Returns `Ok(None)` if no such
149149
/// key exists.
150150
async fn get_maybe<T: DeserializeOwned>(storage: &Storage, key: &str) -> Result<Option<T>> {
151-
let res = storage.get::<T>(key).await;
152-
153-
// Return None if the result of the get is
154-
// worker::Error::from(JsValue:from("No such value in storage."))
155-
if let Err(Error::JsError(ref e)) = res {
156-
if e == "No such value in storage." {
157-
return Ok(None);
158-
}
151+
match storage.get::<T>(key).await {
152+
Ok(val) => Ok(Some(val)),
153+
// Return None if the result of the get is "No such value in storage."
154+
Err(Error::JsError(ref e)) if e == "No such value in storage." => Ok(None),
155+
Err(e) => Err(e),
159156
}
160-
161-
// In any other case, we either have a real return value or an error
162-
res.map(Option::Some)
163157
}
164158

165159
/// Return a handle for the public R2 bucket from which to serve this log's

0 commit comments

Comments
 (0)