Skip to content

Commit c828c8e

Browse files
committed
Fix legacy NoSuchKey bugs
Signed-off-by: Ryan Levick <[email protected]>
1 parent de37fdd commit c828c8e

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

crates/key-value-redis/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ struct RedisStore {
5555
impl Store for RedisStore {
5656
async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, Error> {
5757
let mut conn = self.connection.lock().await;
58-
let result: Vec<u8> = conn.get(key).await.map_err(log_error)?;
59-
60-
if result.is_empty() {
61-
Ok(None)
62-
} else {
63-
Ok(Some(result))
64-
}
58+
conn.get(key).await.map_err(log_error)
6559
}
6660

6761
async fn set(&self, key: &str, value: &[u8]) -> Result<(), Error> {

crates/key-value/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl key_value::HostStore for KeyValueDispatch {
140140

141141
pub fn log_error(err: impl std::fmt::Debug) -> Error {
142142
tracing::warn!("key-value error: {err:?}");
143-
Error::Io(format!("{err:?}"))
143+
Error::Other(format!("{err:?}"))
144144
}
145145

146146
use spin_world::v1::key_value::Error as LegacyError;
@@ -150,7 +150,7 @@ fn to_legacy_error(value: key_value::Error) -> LegacyError {
150150
Error::StoreTableFull => LegacyError::StoreTableFull,
151151
Error::NoSuchStore => LegacyError::NoSuchStore,
152152
Error::AccessDenied => LegacyError::AccessDenied,
153-
Error::Io(s) => LegacyError::Io(s),
153+
Error::Other(s) => LegacyError::Io(s),
154154
}
155155
}
156156

@@ -166,7 +166,7 @@ impl spin_world::v1::key_value::Host for KeyValueDispatch {
166166
let result = <Self as key_value::HostStore>::get(self, this, key).await?;
167167
Ok(result
168168
.map_err(to_legacy_error)
169-
.map(|v| v.unwrap_or_default()))
169+
.and_then(|v| v.ok_or(LegacyError::NoSuchKey)))
170170
}
171171

172172
async fn set(

crates/key-value/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl CachingStoreState {
123123
if let Some(previous_task) = previous_task {
124124
previous_task
125125
.await
126-
.map_err(|e| Error::Io(format!("{e:?}")))??
126+
.map_err(|e| Error::Other(format!("{e:?}")))??
127127
}
128128

129129
task.await
@@ -134,7 +134,7 @@ impl CachingStoreState {
134134
if let Some(previous_task) = self.previous_task.take() {
135135
previous_task
136136
.await
137-
.map_err(|e| Error::Io(format!("{e:?}")))??
137+
.map_err(|e| Error::Other(format!("{e:?}")))??
138138
}
139139

140140
Ok(())

wit/preview2/key-value.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ interface key-value {
4242
access-denied,
4343

4444
/// Some implementation-specific error has occurred (e.g. I/O)
45-
io(string)
45+
other(string)
4646
}
4747
}

0 commit comments

Comments
 (0)