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 { expected: usize, actual: usize },
14
15 #[error("invalid data length: expected {expected}, got {actual}")]
17 InvalidDataLength { expected: usize, actual: usize },
18
19 #[error("invalid hex string: {0}")]
21 InvalidHex(String),
22
23 #[error("invalid base58 string: {0}")]
25 InvalidBase58(String),
26
27 #[error("invalid base64 string: {0}")]
29 InvalidBase64(String),
30
31 #[error("cryptographic operation failed: {0}")]
33 CryptoError(String),
34
35 #[error("invalid signature: {0}")]
37 InvalidSignature(String),
38
39 #[error("invalid public key: {0}")]
41 InvalidPublicKey(String),
42
43 #[error("invalid private key: {0}")]
45 InvalidPrivateKey(String),
46
47 #[error("point at infinity")]
49 PointAtInfinity,
50
51 #[error("decryption failed")]
53 DecryptionFailed,
54
55 #[error("invalid nonce: {0}")]
57 InvalidNonce(String),
58
59 #[error("invalid authentication tag")]
61 InvalidTag,
62
63 #[error("invalid UTF-8 sequence: {0}")]
65 InvalidUtf8(String),
66
67 #[error("reader underflow: need {needed} bytes, only {available} available")]
69 ReaderUnderflow { needed: usize, available: usize },
70
71 #[error("non-canonical varint: {value} encoded in {width} bytes")]
73 NonCanonicalVarInt { width: u8, value: u64 },
74
75 #[error("compact size too large: {0}")]
77 CompactSizeTooLarge(u64),
78
79 #[error("invalid checksum")]
81 InvalidChecksum,
82
83 #[cfg(feature = "script")]
88 #[error("script parse error: {0}")]
89 ScriptParseError(String),
90
91 #[cfg(feature = "script")]
93 #[error("script execution error: {0}")]
94 ScriptExecutionError(String),
95
96 #[cfg(feature = "script")]
98 #[error("invalid opcode: 0x{0:02x}")]
99 InvalidOpcode(u8),
100
101 #[cfg(feature = "script")]
103 #[error("disabled opcode: 0x{0:02x}")]
104 DisabledOpcode(u8),
105
106 #[cfg(feature = "script")]
108 #[error("stack underflow")]
109 StackUnderflow,
110
111 #[cfg(feature = "script")]
113 #[error("stack overflow")]
114 StackOverflow,
115
116 #[cfg(feature = "script")]
118 #[error("BIP-276 error: {0}")]
119 Bip276Error(String),
120
121 #[cfg(feature = "script")]
123 #[error("invalid address: {0}")]
124 InvalidAddress(String),
125
126 #[cfg(feature = "script")]
128 #[error("invalid address length for '{0}'")]
129 InvalidAddressLength(String),
130
131 #[cfg(feature = "script")]
133 #[error("address not supported {0}")]
134 UnsupportedAddress(String),
135
136 #[cfg(feature = "transaction")]
141 #[error("transaction error: {0}")]
142 TransactionError(String),
143
144 #[cfg(feature = "transaction")]
146 #[error("merkle path error: {0}")]
147 MerklePathError(String),
148
149 #[cfg(feature = "transaction")]
151 #[error("BEEF error: {0}")]
152 BeefError(String),
153
154 #[cfg(feature = "transaction")]
156 #[error("fee model error: {0}")]
157 FeeModelError(String),
158
159 #[cfg(feature = "wallet")]
164 #[error("wallet error: {0}")]
165 WalletError(String),
166
167 #[cfg(feature = "wallet")]
169 #[error("key derivation error: {0}")]
170 KeyDerivationError(String),
171
172 #[cfg(feature = "wallet")]
174 #[error("protocol validation error: {0}")]
175 ProtocolValidationError(String),
176
177 #[cfg(feature = "wallet")]
179 #[error("invalid counterparty: {0}")]
180 InvalidCounterparty(String),
181
182 #[cfg(feature = "messages")]
187 #[error("message version mismatch: expected {expected}, got {actual}")]
188 MessageVersionMismatch { expected: String, actual: String },
189
190 #[cfg(feature = "messages")]
192 #[error("message error: {0}")]
193 MessageError(String),
194
195 #[cfg(feature = "messages")]
197 #[error("message recipient mismatch: expected {expected}, got {actual}")]
198 MessageRecipientMismatch { expected: String, actual: String },
199
200 #[cfg(feature = "compat")]
205 #[error("invalid mnemonic: {0}")]
206 InvalidMnemonic(String),
207
208 #[cfg(feature = "compat")]
210 #[error("invalid entropy length: expected {expected}, got {actual}")]
211 InvalidEntropyLength { expected: String, actual: usize },
212
213 #[cfg(feature = "compat")]
215 #[error("invalid word in mnemonic: {0}")]
216 InvalidMnemonicWord(String),
217
218 #[cfg(feature = "compat")]
220 #[error("invalid extended key: {0}")]
221 InvalidExtendedKey(String),
222
223 #[cfg(feature = "compat")]
225 #[error("cannot derive hardened child from public key")]
226 HardenedFromPublic,
227
228 #[cfg(feature = "compat")]
230 #[error("invalid derivation path: {0}")]
231 InvalidDerivationPath(String),
232
233 #[cfg(feature = "compat")]
235 #[error("ECIES decryption failed: {0}")]
236 EciesDecryptionFailed(String),
237
238 #[cfg(feature = "compat")]
240 #[error("ECIES HMAC verification failed")]
241 EciesHmacMismatch,
242
243 #[cfg(feature = "auth")]
248 #[error("authentication error: {0}")]
249 AuthError(String),
250
251 #[cfg(feature = "auth")]
253 #[error("session not found: {0}")]
254 SessionNotFound(String),
255
256 #[cfg(feature = "auth")]
258 #[error("certificate validation failed: {0}")]
259 CertificateValidationError(String),
260
261 #[cfg(feature = "auth")]
263 #[error("transport error: {0}")]
264 TransportError(String),
265
266 #[cfg(feature = "overlay")]
271 #[error("overlay error: {0}")]
272 OverlayError(String),
273
274 #[cfg(feature = "overlay")]
276 #[error("no hosts found for service: {0}")]
277 NoHostsFound(String),
278
279 #[cfg(feature = "overlay")]
281 #[error("overlay broadcast failed: {0}")]
282 OverlayBroadcastFailed(String),
283
284 #[cfg(feature = "registry")]
289 #[error("registry error: {0}")]
290 RegistryError(String),
291
292 #[cfg(feature = "registry")]
294 #[error("definition not found: {0}")]
295 DefinitionNotFound(String),
296
297 #[cfg(feature = "registry")]
299 #[error("invalid definition data: {0}")]
300 InvalidDefinitionData(String),
301
302 #[cfg(feature = "kvstore")]
307 #[error("kvstore error: {0}")]
308 KvStoreError(String),
309
310 #[cfg(feature = "kvstore")]
312 #[error("kvstore key not found: {0}")]
313 KvStoreKeyNotFound(String),
314
315 #[cfg(feature = "kvstore")]
317 #[error("corrupted kvstore state: {0}")]
318 KvStoreCorruptedState(String),
319
320 #[cfg(feature = "kvstore")]
322 #[error("context cannot be empty")]
323 KvStoreEmptyContext,
324
325 #[cfg(feature = "kvstore")]
327 #[error("invalid key")]
328 KvStoreInvalidKey,
329
330 #[cfg(feature = "kvstore")]
332 #[error("invalid value")]
333 KvStoreInvalidValue,
334
335 #[cfg(feature = "identity")]
340 #[error("identity error: {0}")]
341 IdentityError(String),
342
343 #[cfg(feature = "identity")]
345 #[error("identity not found: {0}")]
346 IdentityNotFound(String),
347
348 #[cfg(feature = "identity")]
350 #[error("contact not found: {0}")]
351 ContactNotFound(String),
352}
353
354pub type Result<T> = std::result::Result<T, Error>;