app

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

commit 940caf07117dfe9f0a5b156d85c3720c12d7aa4f
parent 63aa6d26f5afa24f079451ff7de5e0787bfc2f99
Author: triesap <triesap@radroots.dev>
Date:   Sun, 18 Jan 2026 23:40:16 +0000

app-core: add client geolocation error map

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

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

diff --git a/crates/core/src/geolocation/error.rs b/crates/core/src/geolocation/error.rs @@ -0,0 +1,85 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsClientGeolocationError { + PermissionDenied, + LocationUnavailable, + PositionUnavailable, + Timeout, + BlockedByPermissionsPolicy, + UnknownError, +} + +pub type RadrootsClientGeolocationErrorMessage = &'static str; + +impl RadrootsClientGeolocationError { + pub const fn message(self) -> RadrootsClientGeolocationErrorMessage { + match self { + RadrootsClientGeolocationError::PermissionDenied => { + "error.client.geolocation.permission_denied" + } + RadrootsClientGeolocationError::LocationUnavailable => { + "error.client.geolocation.location_unavailable" + } + RadrootsClientGeolocationError::PositionUnavailable => { + "error.client.geolocation.position_unavailable" + } + RadrootsClientGeolocationError::Timeout => { + "error.client.geolocation.timeout" + } + RadrootsClientGeolocationError::BlockedByPermissionsPolicy => { + "error.client.geolocation.blocked_by_permissions_policy" + } + RadrootsClientGeolocationError::UnknownError => { + "error.client.geolocation.unknown_error" + } + } + } +} + +impl fmt::Display for RadrootsClientGeolocationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsClientGeolocationError {} + +#[cfg(test)] +mod tests { + use super::RadrootsClientGeolocationError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsClientGeolocationError::PermissionDenied, + "error.client.geolocation.permission_denied", + ), + ( + RadrootsClientGeolocationError::LocationUnavailable, + "error.client.geolocation.location_unavailable", + ), + ( + RadrootsClientGeolocationError::PositionUnavailable, + "error.client.geolocation.position_unavailable", + ), + ( + RadrootsClientGeolocationError::Timeout, + "error.client.geolocation.timeout", + ), + ( + RadrootsClientGeolocationError::BlockedByPermissionsPolicy, + "error.client.geolocation.blocked_by_permissions_policy", + ), + ( + RadrootsClientGeolocationError::UnknownError, + "error.client.geolocation.unknown_error", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +} diff --git a/crates/core/src/geolocation/mod.rs b/crates/core/src/geolocation/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::{RadrootsClientGeolocationError, RadrootsClientGeolocationErrorMessage}; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs @@ -5,3 +5,4 @@ pub mod cipher; pub mod backup; pub mod datastore; pub mod fs; +pub mod geolocation;