commit 2c661965592796e0a4548d09fd47316876cc9f61
parent 940caf07117dfe9f0a5b156d85c3720c12d7aa4f
Author: triesap <triesap@radroots.dev>
Date: Sun, 18 Jan 2026 23:43:46 +0000
app-core: add client keystore error map
- add keystore module scaffold to radroots-app-core
- define RadrootsClientKeystoreError with message mapping
- implement Display/Error for keystore error enum
- cover keystore error messages with unit tests
Diffstat:
3 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/crates/core/src/keystore/error.rs b/crates/core/src/keystore/error.rs
@@ -0,0 +1,69 @@
+use std::fmt;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RadrootsClientKeystoreError {
+ IdbUndefined,
+ MissingKey,
+ CorruptData,
+ NostrInvalidSecretKey,
+ NostrNoResults,
+}
+
+pub type RadrootsClientKeystoreErrorMessage = &'static str;
+
+impl RadrootsClientKeystoreError {
+ pub const fn message(self) -> RadrootsClientKeystoreErrorMessage {
+ match self {
+ RadrootsClientKeystoreError::IdbUndefined => "error.client.keystore.idb_undefined",
+ RadrootsClientKeystoreError::MissingKey => "error.client.keystore.missing_key",
+ RadrootsClientKeystoreError::CorruptData => "error.client.keystore.corrupt_data",
+ RadrootsClientKeystoreError::NostrInvalidSecretKey => {
+ "error.client.keystore.nostr_invalid_secret_key"
+ }
+ RadrootsClientKeystoreError::NostrNoResults => "error.client.keystore.nostr_no_results",
+ }
+ }
+}
+
+impl fmt::Display for RadrootsClientKeystoreError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(self.message())
+ }
+}
+
+impl std::error::Error for RadrootsClientKeystoreError {}
+
+#[cfg(test)]
+mod tests {
+ use super::RadrootsClientKeystoreError;
+
+ #[test]
+ fn message_matches_spec() {
+ let cases = [
+ (
+ RadrootsClientKeystoreError::IdbUndefined,
+ "error.client.keystore.idb_undefined",
+ ),
+ (
+ RadrootsClientKeystoreError::MissingKey,
+ "error.client.keystore.missing_key",
+ ),
+ (
+ RadrootsClientKeystoreError::CorruptData,
+ "error.client.keystore.corrupt_data",
+ ),
+ (
+ RadrootsClientKeystoreError::NostrInvalidSecretKey,
+ "error.client.keystore.nostr_invalid_secret_key",
+ ),
+ (
+ RadrootsClientKeystoreError::NostrNoResults,
+ "error.client.keystore.nostr_no_results",
+ ),
+ ];
+ for (err, expected) in cases {
+ assert_eq!(err.message(), expected);
+ assert_eq!(err.to_string(), expected);
+ }
+ }
+}
diff --git a/crates/core/src/keystore/mod.rs b/crates/core/src/keystore/mod.rs
@@ -0,0 +1,3 @@
+pub mod error;
+
+pub use error::{RadrootsClientKeystoreError, RadrootsClientKeystoreErrorMessage};
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
@@ -6,3 +6,4 @@ pub mod backup;
pub mod datastore;
pub mod fs;
pub mod geolocation;
+pub mod keystore;