#[cfg(feature = "nns-host")]
use crate::{nns::NnsGovernanceQueryError, runtime::RuntimeError};
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum NnsGovernanceError {
#[error("direct NNS Governance reports support only the mainnet `ic` network, not {network:?}")]
UnsupportedNetwork {
network: String,
},
#[error("invalid NNS Governance source selection: {reason}")]
InvalidSourceSelection {
reason: String,
},
#[error("NNS Governance source evidence does not match the request: {reason}")]
SourceEvidenceMismatch {
reason: String,
},
#[error("failed to build IC agent for {endpoint}: {reason}")]
AgentBuild {
endpoint: String,
reason: String,
},
#[error("NNS Governance agent call {method} failed: {reason}")]
AgentCall {
method: &'static str,
reason: String,
},
#[error("NNS Governance inter-canister call {method} failed: {reason}")]
InterCanisterCall {
method: &'static str,
reason: String,
},
#[error(
"NNS Governance inter-canister call {method} was rejected with code {reject_code}: {message}"
)]
InterCanisterCallRejected {
method: &'static str,
reject_code: u32,
message: String,
},
#[error("failed to encode Candid {message}: {reason}")]
CandidEncode {
message: &'static str,
reason: String,
},
#[error("failed to decode Candid {message}: {reason}")]
CandidDecode {
message: &'static str,
reason: String,
},
#[error("NNS Governance {method} response was {actual_bytes} bytes; limit is {maximum_bytes}")]
ResponseTooLarge {
method: &'static str,
actual_bytes: usize,
maximum_bytes: usize,
},
#[error("NNS Governance rejected the metrics query with code {error_type}: {message}")]
Governance {
error_type: i32,
message: String,
},
#[error("NNS Governance metric {field} bucket {key} has non-finite value {value}")]
InvalidMetrics {
field: &'static str,
key: u64,
value: f64,
},
}
#[cfg(feature = "nns-host")]
impl From<NnsGovernanceQueryError> for NnsGovernanceError {
fn from(value: NnsGovernanceQueryError) -> Self {
match value {
NnsGovernanceQueryError::AgentBuild { endpoint, reason } => {
Self::AgentBuild { endpoint, reason }
}
NnsGovernanceQueryError::AgentCall { method, reason } => {
Self::AgentCall { method, reason }
}
NnsGovernanceQueryError::CandidEncode { message, reason } => {
Self::CandidEncode { message, reason }
}
NnsGovernanceQueryError::CandidDecode { message, reason } => {
Self::CandidDecode { message, reason }
}
}
}
}
#[cfg(feature = "nns-host")]
#[derive(Debug, ThisError)]
pub enum NnsGovernanceHostError {
#[error(transparent)]
Governance(#[from] NnsGovernanceError),
#[error(transparent)]
Runtime(#[from] RuntimeError),
}