1use thiserror::Error;
4
5#[derive(Error, Debug, Clone, PartialEq, Eq)]
7pub enum Error {
8 #[error("invalid key length: expected {expected}, got {actual}")]
13 InvalidKeyLength {
14 expected: usize,
16 actual: usize,
18 },
19
20 #[error("invalid data length: expected {expected}, got {actual}")]
22 InvalidDataLength {
23 expected: usize,
25 actual: usize,
27 },
28
29 #[error("invalid hex string: {0}")]
31 InvalidHex(String),
32
33 #[error("invalid base58 string: {0}")]
35 InvalidBase58(String),
36
37 #[error("invalid base64 string: {0}")]
39 InvalidBase64(String),
40
41 #[error("cryptographic operation failed: {0}")]
43 CryptoError(String),
44
45 #[error("invalid signature: {0}")]
47 InvalidSignature(String),
48
49 #[error("invalid public key: {0}")]
51 InvalidPublicKey(String),
52
53 #[error("invalid private key: {0}")]
55 InvalidPrivateKey(String),
56
57 #[error("point at infinity")]
59 PointAtInfinity,
60
61 #[error("decryption failed")]
63 DecryptionFailed,
64
65 #[error("invalid nonce: {0}")]
67 InvalidNonce(String),
68
69 #[error("invalid authentication tag")]
71 InvalidTag,
72
73 #[error("invalid UTF-8 sequence: {0}")]
75 InvalidUtf8(String),
76
77 #[error("reader underflow: need {needed} bytes, only {available} available")]
79 ReaderUnderflow {
80 needed: usize,
82 available: usize,
84 },
85
86 #[error("non-canonical varint: {value} encoded in {width} bytes")]
88 NonCanonicalVarInt {
89 width: u8,
91 value: u64,
93 },
94
95 #[error("compact size too large: {0}")]
97 CompactSizeTooLarge(u64),
98
99 #[error("invalid checksum")]
101 InvalidChecksum,
102
103 #[cfg(feature = "script")]
108 #[error("script parse error: {0}")]
109 ScriptParseError(String),
110
111 #[cfg(feature = "script")]
113 #[error("script execution error: {0}")]
114 ScriptExecutionError(String),
115
116 #[cfg(feature = "script")]
118 #[error("invalid opcode: 0x{0:02x}")]
119 InvalidOpcode(u8),
120
121 #[cfg(feature = "script")]
123 #[error("disabled opcode: 0x{0:02x}")]
124 DisabledOpcode(u8),
125
126 #[cfg(feature = "script")]
128 #[error("stack underflow")]
129 StackUnderflow,
130
131 #[cfg(feature = "script")]
133 #[error("stack overflow")]
134 StackOverflow,
135
136 #[cfg(feature = "script")]
138 #[error("BIP-276 error: {0}")]
139 Bip276Error(String),
140
141 #[cfg(feature = "script")]
143 #[error("invalid address: {0}")]
144 InvalidAddress(String),
145
146 #[cfg(feature = "script")]
148 #[error("invalid address length for '{0}'")]
149 InvalidAddressLength(String),
150
151 #[cfg(feature = "script")]
153 #[error("address not supported {0}")]
154 UnsupportedAddress(String),
155
156 #[cfg(feature = "transaction")]
161 #[error("transaction error: {0}")]
162 TransactionError(String),
163
164 #[cfg(feature = "transaction")]
166 #[error("merkle path error: {0}")]
167 MerklePathError(String),
168
169 #[cfg(feature = "transaction")]
171 #[error("BEEF error: {0}")]
172 BeefError(String),
173
174 #[cfg(feature = "transaction")]
176 #[error("fee model error: {0}")]
177 FeeModelError(String),
178
179 #[cfg(feature = "wallet")]
184 #[error("wallet error: {0}")]
185 WalletError(String),
186
187 #[cfg(feature = "wallet")]
189 #[error("key derivation error: {0}")]
190 KeyDerivationError(String),
191
192 #[cfg(feature = "wallet")]
194 #[error("protocol validation error: {0}")]
195 ProtocolValidationError(String),
196
197 #[cfg(feature = "wallet")]
199 #[error("invalid counterparty: {0}")]
200 InvalidCounterparty(String),
201
202 #[cfg(feature = "messages")]
207 #[error("message version mismatch: expected {expected}, got {actual}")]
208 MessageVersionMismatch {
209 expected: String,
211 actual: String,
213 },
214
215 #[cfg(feature = "messages")]
217 #[error("message error: {0}")]
218 MessageError(String),
219
220 #[cfg(feature = "messages")]
222 #[error("message recipient mismatch: expected {expected}, got {actual}")]
223 MessageRecipientMismatch {
224 expected: String,
226 actual: String,
228 },
229
230 #[cfg(feature = "compat")]
235 #[error("invalid mnemonic: {0}")]
236 InvalidMnemonic(String),
237
238 #[cfg(feature = "compat")]
240 #[error("invalid entropy length: expected {expected}, got {actual}")]
241 InvalidEntropyLength {
242 expected: String,
244 actual: usize,
246 },
247
248 #[cfg(feature = "compat")]
250 #[error("invalid word in mnemonic: {0}")]
251 InvalidMnemonicWord(String),
252
253 #[cfg(feature = "compat")]
255 #[error("invalid extended key: {0}")]
256 InvalidExtendedKey(String),
257
258 #[cfg(feature = "compat")]
260 #[error("cannot derive hardened child from public key")]
261 HardenedFromPublic,
262
263 #[cfg(feature = "compat")]
265 #[error("invalid derivation path: {0}")]
266 InvalidDerivationPath(String),
267
268 #[cfg(feature = "compat")]
270 #[error("ECIES decryption failed: {0}")]
271 EciesDecryptionFailed(String),
272
273 #[cfg(feature = "compat")]
275 #[error("ECIES HMAC verification failed")]
276 EciesHmacMismatch,
277
278 #[cfg(feature = "auth")]
283 #[error("authentication error: {0}")]
284 AuthError(String),
285
286 #[cfg(feature = "auth")]
288 #[error("session not found: {0}")]
289 SessionNotFound(String),
290
291 #[cfg(feature = "auth")]
293 #[error("certificate validation failed: {0}")]
294 CertificateValidationError(String),
295
296 #[cfg(feature = "auth")]
298 #[error("transport error: {0}")]
299 TransportError(String),
300
301 #[cfg(feature = "overlay")]
306 #[error("overlay error: {0}")]
307 OverlayError(String),
308
309 #[cfg(feature = "overlay")]
311 #[error("no hosts found for service: {0}")]
312 NoHostsFound(String),
313
314 #[cfg(feature = "overlay")]
316 #[error("overlay broadcast failed: {0}")]
317 OverlayBroadcastFailed(String),
318
319 #[cfg(feature = "registry")]
324 #[error("registry error: {0}")]
325 RegistryError(String),
326
327 #[cfg(feature = "registry")]
329 #[error("definition not found: {0}")]
330 DefinitionNotFound(String),
331
332 #[cfg(feature = "registry")]
334 #[error("invalid definition data: {0}")]
335 InvalidDefinitionData(String),
336
337 #[cfg(feature = "kvstore")]
342 #[error("kvstore error: {0}")]
343 KvStoreError(String),
344
345 #[cfg(feature = "kvstore")]
347 #[error("kvstore key not found: {0}")]
348 KvStoreKeyNotFound(String),
349
350 #[cfg(feature = "kvstore")]
352 #[error("corrupted kvstore state: {0}")]
353 KvStoreCorruptedState(String),
354
355 #[cfg(feature = "kvstore")]
357 #[error("context cannot be empty")]
358 KvStoreEmptyContext,
359
360 #[cfg(feature = "kvstore")]
362 #[error("invalid key")]
363 KvStoreInvalidKey,
364
365 #[cfg(feature = "kvstore")]
367 #[error("invalid value")]
368 KvStoreInvalidValue,
369
370 #[cfg(feature = "identity")]
375 #[error("identity error: {0}")]
376 IdentityError(String),
377
378 #[cfg(feature = "identity")]
380 #[error("identity not found: {0}")]
381 IdentityNotFound(String),
382
383 #[cfg(feature = "identity")]
385 #[error("contact not found: {0}")]
386 ContactNotFound(String),
387}
388
389pub type Result<T> = std::result::Result<T, Error>;