Skip to main content

somnia_core/
error.rs

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 {
11        field: String,
12        expected: String,
13        got: String,
14    },
15    #[error("connection: {0}")]
16    Connection(String),
17    #[error("migration: {0}")]
18    Migration(String),
19    #[error("serde: {0}")]
20    Serde(#[from] serde_json::Error),
21    #[error("{0}")]
22    Message(String),
23}
24
25impl SomniaError {
26    pub fn query(msg: impl Into<String>) -> Self {
27        Self::Query(msg.into())
28    }
29    pub fn deser(msg: impl Into<String>) -> Self {
30        Self::Deser(msg.into())
31    }
32    pub fn missing(field: impl Into<String>) -> Self {
33        Self::MissingField(field.into())
34    }
35    pub fn msg(msg: impl Into<String>) -> Self {
36        Self::Message(msg.into())
37    }
38    pub fn migration(msg: impl Into<String>) -> Self {
39        Self::Migration(msg.into())
40    }
41}