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("authentication: {0}")]
18 Auth(String),
19 #[error("migration: {0}")]
20 Migration(String),
21 #[error("serde: {0}")]
22 Serde(#[from] serde_json::Error),
23 #[error("{0}")]
24 Message(String),
25}
26
27impl SomniaError {
28 pub fn query(msg: impl Into<String>) -> Self {
29 Self::Query(msg.into())
30 }
31 pub fn deser(msg: impl Into<String>) -> Self {
32 Self::Deser(msg.into())
33 }
34 pub fn missing(field: impl Into<String>) -> Self {
35 Self::MissingField(field.into())
36 }
37 pub fn msg(msg: impl Into<String>) -> Self {
38 Self::Message(msg.into())
39 }
40 pub fn migration(msg: impl Into<String>) -> Self {
41 Self::Migration(msg.into())
42 }
43 pub fn auth(msg: impl Into<String>) -> Self {
44 Self::Auth(msg.into())
45 }
46}