app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit d81e25f4557fe4d4851239958d2ce6559aa4edfc
parent f8d894a1d67ca17d4b1f15946be7e9432db2f7df
Author: triesap <triesap@radroots.dev>
Date:   Sun, 18 Jan 2026 23:33:18 +0000

app-core: add client datastore error map

- add datastore module scaffold to radroots-app-core
- define RadrootsClientDatastoreError with message mapping
- implement Display/Error for datastore error enum
- cover datastore error messages with unit tests

Diffstat:
Acrates/core/src/datastore/error.rs | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/core/src/datastore/mod.rs | 3+++
Mcrates/core/src/lib.rs | 1+
3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/crates/core/src/datastore/error.rs b/crates/core/src/datastore/error.rs @@ -0,0 +1,49 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsClientDatastoreError { + IdbUndefined, + NoResult, +} + +pub type RadrootsClientDatastoreErrorMessage = &'static str; + +impl RadrootsClientDatastoreError { + pub const fn message(self) -> RadrootsClientDatastoreErrorMessage { + match self { + RadrootsClientDatastoreError::IdbUndefined => "error.client.datastore.idb_undefined", + RadrootsClientDatastoreError::NoResult => "error.client.datastore.no_result", + } + } +} + +impl fmt::Display for RadrootsClientDatastoreError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsClientDatastoreError {} + +#[cfg(test)] +mod tests { + use super::RadrootsClientDatastoreError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsClientDatastoreError::IdbUndefined, + "error.client.datastore.idb_undefined", + ), + ( + RadrootsClientDatastoreError::NoResult, + "error.client.datastore.no_result", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +} diff --git a/crates/core/src/datastore/mod.rs b/crates/core/src/datastore/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::{RadrootsClientDatastoreError, RadrootsClientDatastoreErrorMessage}; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs @@ -3,3 +3,4 @@ pub mod crypto; pub mod cipher; pub mod backup; +pub mod datastore;