1#[derive(Debug, thiserror::Error)]
2pub enum SomniaError {
3 #[error("query: {0}")]
4 Query(String),
5 #[error("deserialization: {0}")]
6 Deser(String),
7 #[error("missing field '{0}'")]
8 MissingField(String),
9 #[error("type mismatch for '{field}': expected {expected}, got {got}")]
10 TypeMismatch { field: String, expected: String, got: String },
11 #[error("connection: {0}")]
12 Connection(String),
13 #[error("migration: {0}")]
14 Migration(String),
15 #[error("serde: {0}")]
16 Serde(#[from] serde_json::Error),
17 #[error("{0}")]
18 Message(String),
19}
20
21impl SomniaError {
22 pub fn query(msg: impl Into<String>) -> Self { Self::Query(msg.into()) }
23 pub fn deser(msg: impl Into<String>) -> Self { Self::Deser(msg.into()) }
24 pub fn missing(field: impl Into<String>) -> Self { Self::MissingField(field.into()) }
25 pub fn msg(msg: impl Into<String>) -> Self { Self::Message(msg.into()) }
26 pub fn migration(msg: impl Into<String>) -> Self { Self::Migration(msg.into()) }
27}