app

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

commit c7549f831bb873e26367dc292853b83fc7b80af6
parent d7a5007ee128443f7b8a2cac9bb0138095f7d37e
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 00:16:59 +0000

app-core: add tangle error mapping

- add tangle module exports to core crate
- define tangle error enum with message mapping
- implement Display/Error for tangle error messages
- add unit tests covering tangle error strings

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

diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs @@ -10,3 +10,4 @@ pub mod keystore; pub mod notifications; pub mod radroots; pub mod sql; +pub mod tangle; diff --git a/crates/core/src/tangle/error.rs b/crates/core/src/tangle/error.rs @@ -0,0 +1,73 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsClientTangleError { + InitFailure, + ParseFailure, + InvalidResponse, + RuntimeUnavailable, + CryptoUnavailable, +} + +pub type RadrootsClientTangleErrorMessage = &'static str; + +impl RadrootsClientTangleError { + pub const fn message(self) -> RadrootsClientTangleErrorMessage { + match self { + RadrootsClientTangleError::InitFailure => "error.client.tangle.init_failure", + RadrootsClientTangleError::ParseFailure => "error.client.tangle.parse_failure", + RadrootsClientTangleError::InvalidResponse => { + "error.client.tangle.invalid_response" + } + RadrootsClientTangleError::RuntimeUnavailable => { + "error.client.tangle.runtime_unavailable" + } + RadrootsClientTangleError::CryptoUnavailable => { + "error.client.tangle.crypto_unavailable" + } + } + } +} + +impl fmt::Display for RadrootsClientTangleError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsClientTangleError {} + +#[cfg(test)] +mod tests { + use super::RadrootsClientTangleError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsClientTangleError::InitFailure, + "error.client.tangle.init_failure", + ), + ( + RadrootsClientTangleError::ParseFailure, + "error.client.tangle.parse_failure", + ), + ( + RadrootsClientTangleError::InvalidResponse, + "error.client.tangle.invalid_response", + ), + ( + RadrootsClientTangleError::RuntimeUnavailable, + "error.client.tangle.runtime_unavailable", + ), + ( + RadrootsClientTangleError::CryptoUnavailable, + "error.client.tangle.crypto_unavailable", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +} diff --git a/crates/core/src/tangle/mod.rs b/crates/core/src/tangle/mod.rs @@ -0,0 +1,3 @@ +pub mod error; + +pub use error::{RadrootsClientTangleError, RadrootsClientTangleErrorMessage};