1use fedimint_api_client::api::{ClientConfigDownloadError, FederationError};
8pub use fedimint_client_module::error::*;
9use fedimint_core::core::{ModuleInstanceId, ModuleKind};
10use fedimint_core::db::{DatabaseError, DbMigrationError};
11use fedimint_core::encoding::DecodeError;
12pub use fedimint_eventlog::EventHandlerError;
13use thiserror::Error;
14
15#[derive(Debug, Error)]
17#[non_exhaustive]
18pub enum ClientSecretError {
19 #[error("An encoded client secret already exists and cannot be overwritten")]
21 AlreadyExists,
22
23 #[error("No encoded client secret is present in the database")]
25 NotPresent,
26
27 #[error("The stored client secret could not be decoded")]
29 Decode(#[from] DecodeError),
30}
31
32#[derive(Debug, Error)]
34#[non_exhaustive]
35pub enum ClientBuildError {
36 #[error("The client database is not initialized")]
38 DatabaseNotInitialized,
39
40 #[error("The client database is already initialized")]
43 DatabaseAlreadyInitialized,
44
45 #[error("The secret does not match the one this database was created with")]
47 SecretMismatch,
48
49 #[error("Failed to download the client config")]
51 ConfigDownload(#[source] Box<ClientConfigDownloadError>),
52
53 #[error("Failed to decode the client config")]
56 ConfigDecode(#[from] DecodeError),
57
58 #[error("Failed to migrate the client database")]
60 Migration(#[from] DbMigrationError),
61
62 #[error("Module {instance_id} ({kind}) failed to prepare its recovery")]
65 ModuleRecoveryPrepare {
66 kind: ModuleKind,
68 instance_id: ModuleInstanceId,
70 #[source]
72 source: Box<dyn std::error::Error + Send + Sync>,
73 },
74
75 #[error("Module {instance_id} ({kind}) failed to initialize")]
78 ModuleInit {
79 kind: ModuleKind,
81 instance_id: ModuleInstanceId,
83 #[source]
85 source: Box<dyn std::error::Error + Send + Sync>,
86 },
87
88 #[error("Database error")]
90 Database(#[from] DatabaseError),
91
92 #[error("The client is already stopped")]
94 AlreadyStopped,
95}
96
97impl From<ClientConfigDownloadError> for ClientBuildError {
98 fn from(source: ClientConfigDownloadError) -> Self {
99 Self::ConfigDownload(Box::new(source))
100 }
101}
102
103#[derive(Debug, Error)]
105#[non_exhaustive]
106pub enum BackupError {
107 #[error("Cannot back up while a module recovery is still running")]
109 PendingRecoveries,
110
111 #[error("The federation could not be reached")]
113 Federation(#[source] Box<FederationError>),
114
115 #[error("Module {instance_id} failed to produce its backup")]
118 Module {
119 instance_id: ModuleInstanceId,
121 #[source]
123 source: Box<dyn std::error::Error + Send + Sync>,
124 },
125
126 #[error("The backup payload is {size} bytes, over the limit of {max}")]
128 TooLarge {
129 size: usize,
131 max: usize,
133 },
134
135 #[error("The backup could not be encrypted or decrypted")]
137 Encryption(#[source] Box<dyn std::error::Error + Send + Sync>),
138
139 #[error("The backup could not be decoded")]
141 Decode(#[from] DecodeError),
142}
143
144impl From<FederationError> for BackupError {
145 fn from(source: FederationError) -> Self {
146 Self::Federation(Box::new(source))
147 }
148}
149
150#[derive(Debug, Error)]
152#[non_exhaustive]
153pub enum RecoveryError {
154 #[error("Recovery of module {module_instance_id} failed: {error}")]
161 Failed {
162 module_instance_id: ModuleInstanceId,
164 error: String,
166 },
167
168 #[error("The client shut down before the recovery finished")]
170 ClientStopped,
171}
172
173#[cfg(feature = "uniffi")]
174impl From<RecoveryError> for fedimint_core::util::ffi::UniffiError {
175 fn from(e: RecoveryError) -> Self {
176 Self::General(e.to_string())
177 }
178}