Skip to main content

ic_query/icrc/model/
error.rs

1//! Module: icrc::model::error
2//!
3//! Responsibility: typed errors for generic ICRC parsing, reports, and live calls.
4//! Does not own: command dispatch, host calls, or output policy.
5//! Boundary: preserves one public error surface for reusable ICRC query behavior.
6
7#[cfg(feature = "host")]
8use crate::runtime::RuntimeError;
9use thiserror::Error as ThisError;
10
11///
12/// IcrcError
13///
14/// Error surfaced by generic ICRC validation, report building, and live calls.
15///
16
17#[derive(Debug, ThisError)]
18pub enum IcrcError {
19    #[cfg(feature = "host")]
20    #[error("failed to create Tokio runtime for ICRC query: {0}")]
21    Runtime(#[from] RuntimeError),
22
23    #[error("failed to build IC agent for endpoint {endpoint}: {reason}")]
24    AgentBuild { endpoint: String, reason: String },
25
26    #[error("invalid {field}: {reason}")]
27    InvalidPrincipal { field: &'static str, reason: String },
28
29    #[error("invalid subaccount hex: {reason}")]
30    InvalidSubaccountHex { reason: String },
31
32    #[error("invalid subaccount length: expected 32 bytes, got {bytes}")]
33    InvalidSubaccountLength { bytes: usize },
34
35    #[error("failed to encode Candid request for {message}: {reason}")]
36    CandidEncode {
37        message: &'static str,
38        reason: String,
39    },
40
41    #[error("ICRC ledger method {method} failed: {reason}")]
42    AgentCall {
43        method: &'static str,
44        reason: String,
45    },
46
47    #[error("failed to decode Candid response {message}: {reason}")]
48    CandidDecode {
49        message: &'static str,
50        reason: String,
51    },
52}