From b910f25cc778fb0ce84983be0af2250265ba108a Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Tue, 7 Apr 2020 21:31:10 +0800 Subject: [PATCH] store: do not panic when kv reads null instead, return an empty string. --- src/store.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/store.rs b/src/store.rs index ba521ec..5878464 100644 --- a/src/store.rs +++ b/src/store.rs @@ -14,8 +14,9 @@ extern "C" { fn kv_put_str(key: &str, value: &str) -> Promise; } +// Returns empty string ("") if the key is not found pub async fn get_str(key: &str) -> MyResult { - Ok(JsFuture::from(kv_get(key)).await.internal_err()?.as_string().unwrap()) + Ok(JsFuture::from(kv_get(key)).await.internal_err()?.as_string().unwrap_or("".into())) } pub async fn get_obj(key: &str) -> MyResult {