Skip to content

Commit 9219501

Browse files
committed
tweak(metadb): swap NotFound error with MetaNotFound
1 parent 2c9224d commit 9219501

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub enum ForcepError {
6969
MetaSer(bson::ser::Error),
7070
/// Error with metadata sled database operation
7171
MetaDb(sled::Error),
72+
/// The entry was found successfully, but the metadata was strangely not present
73+
MetaNotFound,
7274
/// The entry for the specified key is not found
7375
NotFound,
7476
}
@@ -84,6 +86,7 @@ impl std::fmt::Display for ForcepError {
8486
Self::MetaDe(e) => write!(fmt, "there was a problem deserializing metadata: {}", e),
8587
Self::MetaSer(e) => write!(fmt, "there was a problem serializing metadata: {}", e),
8688
Self::MetaDb(e) => write!(fmt, "an error with the metadata database occurred: {}", e),
89+
Self::MetaNotFound => write!(fmt, "the entry for the key provided was found, but the metadata was strangely not present"),
8790
Self::NotFound => write!(fmt, "the entry for the key provided was not found"),
8891
}
8992
}
@@ -95,6 +98,7 @@ impl error::Error for ForcepError {
9598
Self::MetaDe(e) => Some(e),
9699
Self::MetaSer(e) => Some(e),
97100
Self::MetaDb(e) => Some(e),
101+
Self::MetaNotFound => None,
98102
Self::NotFound => None,
99103
}
100104
}

src/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl MetaDb {
175175
pub fn get_metadata(&self, key: &[u8]) -> Result<Metadata> {
176176
let data = match self.db.get(key) {
177177
Ok(Some(data)) => data,
178-
Ok(None) => return Err(ForcepError::NotFound),
178+
Ok(None) => return Err(ForcepError::MetaNotFound),
179179
Err(e) => return Err(ForcepError::MetaDb(e)),
180180
};
181181
Metadata::deserialize(&data)
@@ -196,7 +196,7 @@ impl MetaDb {
196196
pub fn remove_metadata_for(&self, key: &[u8]) -> Result<Metadata> {
197197
match self.db.remove(key) {
198198
Ok(Some(m)) => Metadata::deserialize(&m[..]),
199-
Ok(None) => Err(ForcepError::NotFound),
199+
Ok(None) => Err(ForcepError::MetaNotFound),
200200
Err(e) => Err(ForcepError::MetaDb(e)),
201201
}
202202
}
@@ -207,7 +207,7 @@ impl MetaDb {
207207
let mut meta = match self.db.get(key) {
208208
Ok(Some(entry)) => Metadata::deserialize(&entry[..])?,
209209
Err(e) => return Err(ForcepError::MetaDb(e)),
210-
Ok(None) => return Err(ForcepError::NotFound),
210+
Ok(None) => return Err(ForcepError::MetaNotFound),
211211
};
212212
meta.last_accessed = now_since_epoch();
213213
meta.hits += 1;

0 commit comments

Comments
 (0)