use pagedb::PagedbError;
use crate::error::LiteError;
impl From<PagedbError> for LiteError {
fn from(e: PagedbError) -> Self {
if is_corruption(&e) {
return LiteError::Corrupted {
detail: format!("pagedb corruption: {e}"),
};
}
match e {
PagedbError::Quota { .. } => LiteError::Storage {
detail: format!("pagedb quota exceeded: {e}"),
},
PagedbError::Unsupported => LiteError::WorkerFailed {
detail: "pagedb OPFS VFS returned Unsupported — ensure the opfs feature is \
enabled and the worker URL is correct"
.to_string(),
},
other => LiteError::Storage {
detail: other.to_string(),
},
}
}
}
pub(crate) fn is_corruption(e: &PagedbError) -> bool {
matches!(e, PagedbError::Corruption(_) | PagedbError::ChecksumFailure)
}