ic_query/icrc/model/
error.rs1#[cfg(feature = "host")]
8use crate::{HostCacheError, runtime::RuntimeError};
9use std::path::PathBuf;
10use thiserror::Error as ThisError;
11
12#[derive(Debug, ThisError)]
19pub enum IcrcError {
20 #[cfg(feature = "host")]
21 #[error("failed to create Tokio runtime for ICRC query: {0}")]
22 Runtime(#[from] RuntimeError),
23
24 #[error("failed to build IC agent for endpoint {endpoint}: {reason}")]
25 AgentBuild { endpoint: String, reason: String },
26
27 #[error("invalid {field}: {reason}")]
28 InvalidPrincipal { field: &'static str, reason: String },
29
30 #[error("invalid subaccount hex: {reason}")]
31 InvalidSubaccountHex { reason: String },
32
33 #[error("invalid subaccount length: expected 32 bytes, got {bytes}")]
34 InvalidSubaccountLength { bytes: usize },
35
36 #[error("failed to encode Candid request for {message}: {reason}")]
37 CandidEncode {
38 message: &'static str,
39 reason: String,
40 },
41
42 #[error("ICRC ledger method {method} failed: {reason}")]
43 AgentCall {
44 method: &'static str,
45 reason: String,
46 },
47
48 #[error("failed to decode Candid response {message}: {reason}")]
49 CandidDecode {
50 message: &'static str,
51 reason: String,
52 },
53}
54
55#[derive(Debug, ThisError)]
62pub enum IcrcAccountTransactionError {
63 #[error("invalid ICRC account transaction source endpoint {value:?}: {reason}")]
65 InvalidSourceEndpoint {
66 value: String,
68 reason: String,
70 },
71
72 #[error(
74 "invalid ICRC account transaction page size {page_size}; expected between 1 and {max_page_size}"
75 )]
76 InvalidPageSize {
77 page_size: u32,
79 max_page_size: u32,
81 },
82
83 #[error("invalid ICRC account transaction list limit {limit}; expected at least 1")]
85 InvalidListLimit {
86 limit: u32,
88 },
89
90 #[error("invalid ICRC account transaction max pages {max_pages}; expected at least 1")]
92 InvalidMaxPages {
93 max_pages: u32,
95 },
96
97 #[error("invalid ICRC account transaction cursor {value:?}: {reason}")]
99 InvalidCursor {
100 value: String,
102 reason: String,
104 },
105
106 #[error(transparent)]
108 Query(#[from] IcrcError),
109
110 #[error(
112 "failed to discover an index for ledger {ledger_canister_id}; supply an explicit index canister: {source}"
113 )]
114 IndexDiscovery {
115 ledger_canister_id: String,
117 #[source]
119 source: IcrcError,
120 },
121
122 #[error("ledger {ledger_canister_id} has no usable ICRC index: {reason}")]
124 IndexUnavailable {
125 ledger_canister_id: String,
127 reason: String,
129 },
130
131 #[error(
133 "ICRC index {index_canister_id} reports ledger {actual_ledger_canister_id}, expected {expected_ledger_canister_id}"
134 )]
135 IndexLedgerMismatch {
136 index_canister_id: String,
138 expected_ledger_canister_id: String,
140 actual_ledger_canister_id: String,
142 },
143
144 #[error("ICRC index {index_canister_id} account transaction query failed: {message}")]
146 IndexQuery {
147 index_canister_id: String,
149 message: String,
151 },
152
153 #[error(
155 "incomplete ICRC account transaction collection after {pages_fetched} page(s) and {rows_fetched} row(s): {reason}"
156 )]
157 IncompleteCollection {
158 pages_fetched: u32,
160 rows_fetched: usize,
162 last_cursor: Option<String>,
164 reason: String,
166 },
167
168 #[error(
170 "ICRC account transaction collection failed after {pages_fetched} page(s) and {rows_fetched} row(s): {source}"
171 )]
172 CollectionPage {
173 pages_fetched: u32,
175 rows_fetched: usize,
177 last_cursor: Option<String>,
179 #[source]
181 source: Box<Self>,
182 },
183
184 #[error("invalid ICRC account transaction cache at {}: {reason}", path.display())]
186 InvalidCache {
187 path: PathBuf,
189 reason: String,
191 },
192
193 #[error(
195 "invalid ICRC account transaction refresh attempt at {}: {reason}",
196 path.display()
197 )]
198 InvalidRefreshAttempt {
199 path: PathBuf,
201 reason: String,
203 },
204
205 #[cfg(feature = "host")]
207 #[error(transparent)]
208 Cache(#[from] HostCacheError),
209}