1use thiserror::Error;
2
3#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
5#[cfg_attr(feature = "native-bindings", derive(uniffi::Error))]
6pub enum SoftchatError {
7 #[error("invalid secret key")]
9 InvalidSecretKey,
10
11 #[error("invalid public key")]
13 InvalidPublicKey,
14
15 #[error("invalid Nostr event ID")]
17 InvalidEventId,
18
19 #[error("invalid Nostr event signature")]
21 InvalidEventSignature,
22
23 #[error("invalid Nostr event kind")]
25 InvalidEventKind,
26
27 #[error("invalid Nostr event timestamp")]
29 InvalidEventTimestamp,
30
31 #[error("invalid Nostr event tag")]
33 InvalidEventTag,
34
35 #[error("invalid Nostr event JSON")]
37 InvalidEventJson,
38
39 #[error("Nostr event is too large")]
41 EventTooLarge,
42
43 #[error("Nostr event signing failed")]
45 EventSigningFailed,
46
47 #[error("NIP-59 envelope creation failed")]
49 Nip59EnvelopeCreationFailed,
50
51 #[error("invalid NIP-59 envelope")]
53 InvalidNip59Envelope,
54
55 #[error("NIP-17 text message creation failed")]
57 Nip17MessageCreationFailed,
58
59 #[error("invalid NIP-17 text message")]
61 InvalidNip17Message,
62
63 #[error("invalid NIP-19 identifier")]
65 InvalidNip19Identifier,
66
67 #[error("invalid relay frame")]
69 InvalidRelayFrame,
70
71 #[error("invalid relay filter")]
73 InvalidRelayFilter,
74
75 #[error("invalid relay authentication")]
77 InvalidRelayAuthentication,
78
79 #[error("invalid relay batch")]
81 InvalidRelayBatch,
82
83 #[error("invalid attachment metadata")]
85 InvalidAttachmentMetadata,
86
87 #[error("attachment is too large")]
89 AttachmentTooLarge,
90
91 #[error("attachment encryption failed")]
93 AttachmentEncryptionFailed,
94
95 #[error("attachment decryption failed")]
97 AttachmentDecryptionFailed,
98
99 #[error("invalid HTTP authorization request")]
101 InvalidHttpAuthorization,
102
103 #[error("invalid Softchat event")]
105 InvalidSoftchatEvent,
106
107 #[error("Softchat event creation failed")]
109 SoftchatEventCreationFailed,
110
111 #[error("invalid Softchat event projection")]
113 InvalidSoftchatProjection,
114
115 #[error("invalid private user metadata")]
117 InvalidUserMetadata,
118
119 #[error("invalid private contact list")]
121 InvalidContactList,
122
123 #[error("invalid application data")]
125 InvalidApplicationData,
126
127 #[error("invalid relay session transition")]
129 InvalidRelaySession,
130
131 #[error("relay session queue is full")]
133 RelaySessionQueueFull,
134
135 #[error("invalid delivery state")]
137 InvalidDeliveryState,
138
139 #[error("invalid persistence result")]
141 InvalidPersistenceResult,
142
143 #[error("invalid account operation")]
145 InvalidAccountOperation,
146
147 #[error("command identifier conflicts with an existing operation")]
149 CommandConflict,
150
151 #[error("account database is already open")]
153 AccountAlreadyOpen,
154
155 #[error("account is closed")]
157 AccountClosed,
158
159 #[error("invalid account settings")]
161 InvalidAccountSettings,
162
163 #[error("invalid media operation")]
165 InvalidMediaOperation,
166
167 #[error("unsupported system action")]
169 UnsupportedSystemAction,
170
171 #[error("invalid relay catalog")]
173 InvalidRelayCatalog,
174
175 #[error("invalid synchronization state")]
177 InvalidSyncState,
178
179 #[error("invalid Noise handshake")]
181 InvalidNoiseHandshake,
182
183 #[error("Noise handshake is already consumed")]
185 NoiseHandshakeConsumed,
186
187 #[error("Noise session is closed")]
189 NoiseSessionClosed,
190
191 #[error("Noise transport operation failed")]
193 NoiseTransportFailed,
194
195 #[error("invalid Negentropy reconciliation")]
197 InvalidNegentropy,
198
199 #[error("plaintext must not be empty")]
201 EmptyPlaintext,
202
203 #[error("plaintext is too large")]
205 PlaintextTooLarge,
206
207 #[error("invalid encrypted message")]
209 InvalidEncryptedMessage,
210
211 #[error("ciphertext is too large")]
213 CiphertextTooLarge,
214
215 #[error("message encryption failed")]
217 EncryptionFailed,
218
219 #[error("message decryption failed")]
221 DecryptionFailed,
222
223 #[error("identity is erased")]
225 IdentityErased,
226
227 #[error("Softchat operation failed")]
229 InternalFailure,
230}
231
232impl SoftchatError {
233 #[must_use]
235 pub const fn code(&self) -> &'static str {
236 match self {
237 Self::InvalidSecretKey => "invalid_secret_key",
238 Self::InvalidPublicKey => "invalid_public_key",
239 Self::InvalidEventId => "invalid_event_id",
240 Self::InvalidEventSignature => "invalid_event_signature",
241 Self::InvalidEventKind => "invalid_event_kind",
242 Self::InvalidEventTimestamp => "invalid_event_timestamp",
243 Self::InvalidEventTag => "invalid_event_tag",
244 Self::InvalidEventJson => "invalid_event_json",
245 Self::EventTooLarge => "event_too_large",
246 Self::EventSigningFailed => "event_signing_failed",
247 Self::Nip59EnvelopeCreationFailed => "nip59_envelope_creation_failed",
248 Self::InvalidNip59Envelope => "invalid_nip59_envelope",
249 Self::Nip17MessageCreationFailed => "nip17_message_creation_failed",
250 Self::InvalidNip17Message => "invalid_nip17_message",
251 Self::InvalidNip19Identifier => "invalid_nip19_identifier",
252 Self::InvalidRelayFrame => "invalid_relay_frame",
253 Self::InvalidRelayFilter => "invalid_relay_filter",
254 Self::InvalidRelayAuthentication => "invalid_relay_authentication",
255 Self::InvalidRelayBatch => "invalid_relay_batch",
256 Self::InvalidAttachmentMetadata => "invalid_attachment_metadata",
257 Self::AttachmentTooLarge => "attachment_too_large",
258 Self::AttachmentEncryptionFailed => "attachment_encryption_failed",
259 Self::AttachmentDecryptionFailed => "attachment_decryption_failed",
260 Self::InvalidHttpAuthorization => "invalid_http_authorization",
261 Self::InvalidSoftchatEvent => "invalid_softchat_event",
262 Self::SoftchatEventCreationFailed => "softchat_event_creation_failed",
263 Self::InvalidSoftchatProjection => "invalid_softchat_projection",
264 Self::InvalidUserMetadata => "invalid_user_metadata",
265 Self::InvalidContactList => "invalid_contact_list",
266 Self::InvalidApplicationData => "invalid_application_data",
267 Self::InvalidRelaySession => "invalid_relay_session",
268 Self::RelaySessionQueueFull => "relay_session_queue_full",
269 Self::InvalidDeliveryState => "invalid_delivery_state",
270 Self::InvalidPersistenceResult => "invalid_persistence_result",
271 Self::InvalidAccountOperation => "invalid_account_operation",
272 Self::CommandConflict => "command_conflict",
273 Self::AccountAlreadyOpen => "account_already_open",
274 Self::AccountClosed => "account_closed",
275 Self::InvalidAccountSettings => "invalid_account_settings",
276 Self::InvalidMediaOperation => "invalid_media_operation",
277 Self::UnsupportedSystemAction => "unsupported_system_action",
278 Self::InvalidRelayCatalog => "invalid_relay_catalog",
279 Self::InvalidSyncState => "invalid_sync_state",
280 Self::InvalidNoiseHandshake => "invalid_noise_handshake",
281 Self::NoiseHandshakeConsumed => "noise_handshake_consumed",
282 Self::NoiseSessionClosed => "noise_session_closed",
283 Self::NoiseTransportFailed => "noise_transport_failed",
284 Self::InvalidNegentropy => "invalid_negentropy",
285 Self::EmptyPlaintext => "empty_plaintext",
286 Self::PlaintextTooLarge => "plaintext_too_large",
287 Self::InvalidEncryptedMessage => "invalid_encrypted_message",
288 Self::CiphertextTooLarge => "ciphertext_too_large",
289 Self::EncryptionFailed => "encryption_failed",
290 Self::DecryptionFailed => "decryption_failed",
291 Self::IdentityErased => "identity_erased",
292 Self::InternalFailure => "internal_failure",
293 }
294 }
295}