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 across CLI and host features.
6
7#[cfg(feature = "cli")]
8use crate::cli::common::CurrentUnixSecsError;
9#[cfg(feature = "host")]
10use crate::runtime::RuntimeError;
11use std::io;
12use thiserror::Error as ThisError;
13
14///
15/// IcrcError
16///
17/// Error surfaced by generic ICRC command parsing, report building, and live calls.
18///
19
20#[derive(Debug, ThisError)]
21pub enum IcrcError {
22    #[error("{0}")]
23    Usage(String),
24
25    #[cfg(feature = "cli")]
26    #[error(transparent)]
27    Clock(#[from] CurrentUnixSecsError),
28
29    #[cfg(feature = "host")]
30    #[error("failed to create Tokio runtime for ICRC query: {0}")]
31    Runtime(#[from] RuntimeError),
32
33    #[error("failed to build IC agent for endpoint {endpoint}: {reason}")]
34    AgentBuild { endpoint: String, reason: String },
35
36    #[error("invalid {field}: {reason}")]
37    InvalidPrincipal { field: &'static str, reason: String },
38
39    #[error("invalid subaccount hex: {reason}")]
40    InvalidSubaccountHex { reason: String },
41
42    #[error("invalid subaccount length: expected 32 bytes, got {bytes}")]
43    InvalidSubaccountLength { bytes: usize },
44
45    #[error("failed to encode Candid request for {message}: {reason}")]
46    CandidEncode {
47        message: &'static str,
48        reason: String,
49    },
50
51    #[error("ICRC ledger method {method} failed: {reason}")]
52    AgentCall {
53        method: &'static str,
54        reason: String,
55    },
56
57    #[error("failed to decode Candid response {message}: {reason}")]
58    CandidDecode {
59        message: &'static str,
60        reason: String,
61    },
62
63    #[error(transparent)]
64    Io(#[from] io::Error),
65
66    #[error(transparent)]
67    Json(#[from] serde_json::Error),
68}