app

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

commit bf5da943ad5209c9951898c6e711ce2431eed282
parent 72b8e6d6c2b03b6a358a256977c92c23dcb6e4f1
Author: triesap <triesap@radroots.dev>
Date:   Sun, 18 Jan 2026 23:52:56 +0000

app-core: add client radroots error map

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

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

diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs @@ -8,3 +8,4 @@ pub mod fs; pub mod geolocation; pub mod keystore; pub mod notifications; +pub mod radroots; diff --git a/crates/core/src/radroots/error.rs b/crates/core/src/radroots/error.rs @@ -0,0 +1,59 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsClientRadrootsError { + MissingBaseUrl, + AccountRegistered, + RequestFailure, +} + +pub type RadrootsClientRadrootsErrorMessage = &'static str; + +impl RadrootsClientRadrootsError { + pub const fn message(self) -> RadrootsClientRadrootsErrorMessage { + match self { + RadrootsClientRadrootsError::MissingBaseUrl => { + "error.client.radroots.missing_base_url" + } + RadrootsClientRadrootsError::AccountRegistered => { + "error.client.radroots.account_registered" + } + RadrootsClientRadrootsError::RequestFailure => "error.client.radroots.request_failure", + } + } +} + +impl fmt::Display for RadrootsClientRadrootsError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsClientRadrootsError {} + +#[cfg(test)] +mod tests { + use super::RadrootsClientRadrootsError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsClientRadrootsError::MissingBaseUrl, + "error.client.radroots.missing_base_url", + ), + ( + RadrootsClientRadrootsError::AccountRegistered, + "error.client.radroots.account_registered", + ), + ( + RadrootsClientRadrootsError::RequestFailure, + "error.client.radroots.request_failure", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +} diff --git a/crates/core/src/radroots/mod.rs b/crates/core/src/radroots/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::{RadrootsClientRadrootsError, RadrootsClientRadrootsErrorMessage};