Skip to main content

mx_core/
error.rs

1//! Typed error types for mx-core.
2//!
3//! Provides [`CoreError`] so that callers can programmatically distinguish
4//! failure modes without resorting to string matching.
5
6/// Errors returned by mx-core public functions.
7#[derive(Debug, thiserror::Error)]
8pub enum CoreError {
9    /// The input is not a valid bech32 string.
10    #[error("invalid bech32 address: {0}")]
11    InvalidBech32(String),
12
13    /// Decoded address does not have the expected byte length.
14    #[error("invalid address length: expected 32 bytes, got {0}")]
15    InvalidAddressLength(usize),
16
17    /// Address byte slice is empty.
18    #[error("empty address")]
19    EmptyAddress,
20
21    /// BIP39 mnemonic is invalid.
22    #[error("invalid mnemonic: {0}")]
23    InvalidMnemonic(String),
24
25    /// A private key derivation step failed.
26    #[error("invalid private key: {0}")]
27    InvalidPrivateKey(String),
28
29    /// Wallet creation from a derived private key failed.
30    #[error("failed to create wallet: {0}")]
31    WalletCreation(String),
32
33    /// A numeric value could not be parsed.
34    #[error("invalid numeric value: {0}")]
35    InvalidNumeric(String),
36
37    /// A protobuf big integer field does not use the expected Go BigIntCaster encoding.
38    #[error("invalid BigIntCaster encoding: {0}")]
39    InvalidBigIntEncoding(String),
40
41    /// Base64 decoding failed.
42    #[error("invalid base64: {0}")]
43    InvalidBase64(String),
44
45    /// Hex decoding failed.
46    #[error("invalid hex: {0}")]
47    InvalidHex(String),
48
49    /// Bech32 encoding failed.
50    #[error("bech32 encode failed: {0}")]
51    Bech32Encode(String),
52
53    /// HRP (human-readable part) parsing failed during bech32 encoding.
54    #[error("{0}")]
55    InvalidHrp(String),
56}