qorechain/error.rs
1//! Crate-wide error type.
2
3use thiserror::Error;
4
5/// Errors returned across the QoreChain SDK.
6#[derive(Debug, Error)]
7pub enum Error {
8 /// The named network preset is unknown.
9 #[error("unknown network: {0}")]
10 UnknownNetwork(String),
11
12 /// A required endpoint URL was not configured.
13 #[error("endpoint \"{0}\" is not configured — pass it via create_client endpoints")]
14 MissingEndpoint(String),
15
16 /// A decimal/base amount or exponent was invalid.
17 #[error("{0}")]
18 Denom(String),
19
20 /// A bech32 or hex address was invalid.
21 #[error("{0}")]
22 Address(String),
23
24 /// The BIP-39 mnemonic failed word-list and/or checksum validation.
25 #[error("invalid mnemonic")]
26 InvalidMnemonic,
27
28 /// HD derivation produced an invalid key (caller should try the next index).
29 #[error("HD derivation error: {0}")]
30 Derivation(String),
31
32 /// A post-quantum (ML-DSA-87) operation failed.
33 #[error("PQC error: {0}")]
34 Pqc(String),
35
36 /// A non-2xx HTTP response was received.
37 #[error("HTTP {status} for {url}")]
38 Http {
39 /// HTTP status code.
40 status: u16,
41 /// Requested URL.
42 url: String,
43 /// Response body (may be empty).
44 body: String,
45 },
46
47 /// A JSON-RPC response carried an error member.
48 #[error("JSON-RPC error {code}: {message}")]
49 JsonRpc {
50 /// JSON-RPC error code.
51 code: i64,
52 /// JSON-RPC error message.
53 message: String,
54 },
55
56 /// A network/transport error occurred.
57 #[error("transport error: {0}")]
58 Transport(String),
59
60 /// A response body could not be parsed as expected JSON.
61 #[error("invalid response: {0}")]
62 InvalidResponse(String),
63
64 /// A broadcast/confirmed transaction returned a non-zero ABCI result code.
65 #[error(transparent)]
66 Tx(#[from] crate::tx::QoreTxError),
67}
68
69/// Convenience result type used throughout the crate.
70pub type Result<T> = std::result::Result<T, Error>;
71
72impl From<reqwest::Error> for Error {
73 fn from(e: reqwest::Error) -> Self {
74 Error::Transport(e.to_string())
75 }
76}