app

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

commit 5f4e9e6444607f2ca517601e2dafb9561746dbcf
parent 8290eb0e55daf7d8ac483d6b50946d8b54b14e3c
Author: triesap <triesap@radroots.dev>
Date:   Mon, 19 Jan 2026 06:39:05 +0000

app-utils: add utils error type

- define RadrootsAppUtilsError enum
- add error message mapping
- implement Display and Error
- add unit tests for messages

Diffstat:
Mcrates/utils/src/error.rs | 50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs @@ -1 +1,51 @@ #![forbid(unsafe_code)] + +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RadrootsAppUtilsError { + InvalidInput, + Unavailable, +} + +pub type RadrootsAppUtilsErrorMessage = &'static str; + +impl RadrootsAppUtilsError { + pub const fn message(self) -> RadrootsAppUtilsErrorMessage { + match self { + RadrootsAppUtilsError::InvalidInput => "error.app.utils.invalid_input", + RadrootsAppUtilsError::Unavailable => "error.app.utils.unavailable", + } + } +} + +impl fmt::Display for RadrootsAppUtilsError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.message()) + } +} + +impl std::error::Error for RadrootsAppUtilsError {} + +#[cfg(test)] +mod tests { + use super::RadrootsAppUtilsError; + + #[test] + fn message_matches_spec() { + let cases = [ + ( + RadrootsAppUtilsError::InvalidInput, + "error.app.utils.invalid_input", + ), + ( + RadrootsAppUtilsError::Unavailable, + "error.app.utils.unavailable", + ), + ]; + for (err, expected) in cases { + assert_eq!(err.message(), expected); + assert_eq!(err.to_string(), expected); + } + } +}