commit d7a5007ee128443f7b8a2cac9bb0138095f7d37e
parent bf5da943ad5209c9951898c6e711ce2431eed282
Author: triesap <triesap@radroots.dev>
Date: Sun, 18 Jan 2026 23:54:41 +0000
app-core: add client sql error map
- add sql module scaffold to radroots-app-core
- define RadrootsClientSqlError with message mapping
- implement Display/Error for sql error enum
- cover sql error messages with unit tests
Diffstat:
3 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs
@@ -9,3 +9,4 @@ pub mod geolocation;
pub mod keystore;
pub mod notifications;
pub mod radroots;
+pub mod sql;
diff --git a/crates/core/src/sql/error.rs b/crates/core/src/sql/error.rs
@@ -0,0 +1,38 @@
+use std::fmt;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RadrootsClientSqlError {
+ IdbUndefined,
+}
+
+pub type RadrootsClientSqlErrorMessage = &'static str;
+
+impl RadrootsClientSqlError {
+ pub const fn message(self) -> RadrootsClientSqlErrorMessage {
+ match self {
+ RadrootsClientSqlError::IdbUndefined => "error.client.sql.idb_undefined",
+ }
+ }
+}
+
+impl fmt::Display for RadrootsClientSqlError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(self.message())
+ }
+}
+
+impl std::error::Error for RadrootsClientSqlError {}
+
+#[cfg(test)]
+mod tests {
+ use super::RadrootsClientSqlError;
+
+ #[test]
+ fn message_matches_spec() {
+ let cases = [(RadrootsClientSqlError::IdbUndefined, "error.client.sql.idb_undefined")];
+ for (err, expected) in cases {
+ assert_eq!(err.message(), expected);
+ assert_eq!(err.to_string(), expected);
+ }
+ }
+}
diff --git a/crates/core/src/sql/mod.rs b/crates/core/src/sql/mod.rs
@@ -0,0 +1,3 @@
+pub mod error;
+
+pub use error::{RadrootsClientSqlError, RadrootsClientSqlErrorMessage};