1use cdk_common::database::Error as DatabaseError;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
6pub enum Error {
7 #[error(transparent)]
9 Database(#[from] DatabaseError),
10 #[error(transparent)]
12 Reqwest(#[from] reqwest::Error),
13 #[error(transparent)]
15 Url(#[from] url::ParseError),
16 #[error(transparent)]
18 Serde(#[from] serde_json::Error),
19 #[error("Supabase error: {0}")]
21 Supabase(String),
22 #[error(
24 "Schema version mismatch: SDK requires version {required}, \
25 database has version {found}. \
26 An administrator must run migrations to update the database schema."
27 )]
28 SchemaMismatch {
29 required: u32,
31 found: u32,
33 },
34 #[error(
36 "Database schema not initialized. \
37 An administrator must run the initial migrations before clients can connect. \
38 Use `SupabaseWalletDatabase::get_schema_sql()` to get the required SQL."
39 )]
40 SchemaNotInitialized,
41}
42
43impl From<Error> for DatabaseError {
44 fn from(e: Error) -> Self {
45 match e {
46 Error::Database(e) => e,
47 Error::Reqwest(e) => DatabaseError::Database(Box::new(e)),
48 Error::Url(e) => DatabaseError::Database(Box::new(e)),
49 Error::Serde(e) => DatabaseError::Database(Box::new(e)),
50 Error::Supabase(msg) => DatabaseError::Database(Box::new(std::io::Error::other(msg))),
51 Error::SchemaMismatch { required, found } => {
52 DatabaseError::Database(Box::new(std::io::Error::other(format!(
53 "Schema version mismatch: SDK requires version {required}, \
54 database has version {found}. \
55 An administrator must run migrations to update the database schema."
56 ))))
57 }
58 Error::SchemaNotInitialized => {
59 DatabaseError::Database(Box::new(std::io::Error::other(
60 "Database schema not initialized. \
61 An administrator must run the initial migrations before clients can connect.",
62 )))
63 }
64 }
65 }
66}