Skip to main content

cory_core/
error.rs

1//! Error types for cory-core.
2
3use bitcoin::Txid;
4
5// ==============================================================================
6// RPC Errors
7// ==============================================================================
8
9/// Structured errors from the Bitcoin Core JSON-RPC layer.
10///
11/// Each variant captures a specific failure mode rather than collapsing
12/// everything into a single `String`, which makes programmatic error
13/// handling (e.g. retries on transport errors vs. logic errors) possible.
14#[derive(Debug, thiserror::Error)]
15pub enum RpcError {
16    #[error("HTTP transport: {0}")]
17    Transport(#[source] reqwest::Error),
18
19    #[error("JSON-RPC error: code={code}, message={message}")]
20    ServerError { code: i64, message: String },
21
22    #[error("invalid JSON-RPC response: {0}")]
23    InvalidResponse(String),
24
25    #[error("batch response missing item id={id}")]
26    MissingBatchItem { id: u64 },
27}
28
29// ==============================================================================
30// Core Errors
31// ==============================================================================
32
33/// Top-level error type for the cory-core crate.
34#[derive(Debug, thiserror::Error)]
35pub enum CoreError {
36    #[error(transparent)]
37    Rpc(#[from] RpcError),
38
39    #[error("transaction not found: {0}")]
40    TxNotFound(Txid),
41
42    #[error("invalid transaction data: {0}")]
43    InvalidTxData(String),
44
45    #[error("label parse error at line {line}: {message}")]
46    LabelParse { line: usize, message: String },
47
48    #[error(transparent)]
49    Io(#[from] std::io::Error),
50}