ic_query/nns/governance/
error.rs1#[cfg(feature = "nns-host")]
8use crate::{nns::NnsGovernanceQueryError, runtime::RuntimeError};
9use thiserror::Error as ThisError;
10
11#[derive(Debug, ThisError)]
18pub enum NnsGovernanceError {
19 #[error("direct NNS Governance reports support only the mainnet `ic` network, not {network:?}")]
21 UnsupportedNetwork {
22 network: String,
24 },
25
26 #[error("invalid NNS Governance source selection: {reason}")]
28 InvalidSourceSelection {
29 reason: String,
31 },
32
33 #[error("NNS Governance source evidence does not match the request: {reason}")]
35 SourceEvidenceMismatch {
36 reason: String,
38 },
39
40 #[error("failed to build IC agent for {endpoint}: {reason}")]
42 AgentBuild {
43 endpoint: String,
45 reason: String,
47 },
48
49 #[error("NNS Governance agent call {method} failed: {reason}")]
51 AgentCall {
52 method: &'static str,
54 reason: String,
56 },
57
58 #[error("NNS Governance inter-canister call {method} failed: {reason}")]
60 InterCanisterCall {
61 method: &'static str,
63 reason: String,
65 },
66
67 #[error(
69 "NNS Governance inter-canister call {method} was rejected with code {reject_code}: {message}"
70 )]
71 InterCanisterCallRejected {
72 method: &'static str,
74 reject_code: u32,
76 message: String,
78 },
79
80 #[error("failed to encode Candid {message}: {reason}")]
82 CandidEncode {
83 message: &'static str,
85 reason: String,
87 },
88
89 #[error("failed to decode Candid {message}: {reason}")]
91 CandidDecode {
92 message: &'static str,
94 reason: String,
96 },
97
98 #[error("NNS Governance {method} response was {actual_bytes} bytes; limit is {maximum_bytes}")]
100 ResponseTooLarge {
101 method: &'static str,
103 actual_bytes: usize,
105 maximum_bytes: usize,
107 },
108
109 #[error("NNS Governance rejected the metrics query with code {error_type}: {message}")]
111 Governance {
112 error_type: i32,
114 message: String,
116 },
117
118 #[error("NNS Governance metric {field} bucket {key} has non-finite value {value}")]
120 InvalidMetrics {
121 field: &'static str,
123 key: u64,
125 value: f64,
127 },
128}
129
130#[cfg(feature = "nns-host")]
131impl From<NnsGovernanceQueryError> for NnsGovernanceError {
132 fn from(value: NnsGovernanceQueryError) -> Self {
133 match value {
134 NnsGovernanceQueryError::AgentBuild { endpoint, reason } => {
135 Self::AgentBuild { endpoint, reason }
136 }
137 NnsGovernanceQueryError::AgentCall { method, reason } => {
138 Self::AgentCall { method, reason }
139 }
140 NnsGovernanceQueryError::CandidEncode { message, reason } => {
141 Self::CandidEncode { message, reason }
142 }
143 NnsGovernanceQueryError::CandidDecode { message, reason } => {
144 Self::CandidDecode { message, reason }
145 }
146 }
147 }
148}
149
150#[cfg(feature = "nns-host")]
157#[derive(Debug, ThisError)]
158pub enum NnsGovernanceHostError {
159 #[error(transparent)]
161 Governance(#[from] NnsGovernanceError),
162
163 #[error(transparent)]
165 Runtime(#[from] RuntimeError),
166}