app

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

commit 72b8e6d6c2b03b6a358a256977c92c23dcb6e4f1
parent 2c661965592796e0a4548d09fd47316876cc9f61
Author: triesap <triesap@radroots.dev>
Date:   Sun, 18 Jan 2026 23:49:49 +0000

app-core: add client notifications error map

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

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

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