use crate::nns::governance::NnsGovernanceError;
#[cfg(feature = "nns-host")]
use crate::{
HostCacheError, nns::governance::NnsGovernanceAttemptReadError, runtime::RuntimeError,
};
#[cfg(feature = "nns-host")]
use std::path::PathBuf;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum NnsNeuronError {
#[error(transparent)]
Governance(#[from] NnsGovernanceError),
#[error("invalid NNS neuron page size {page_size}; expected 1..={max_page_size}")]
InvalidPageSize {
page_size: u32,
max_page_size: u32,
},
#[error("NNS Governance rejected the neuron query with code {error_type}: {message}")]
GovernanceResponse {
error_type: i32,
message: String,
},
#[error("NNS neuron {neuron_id} was not found")]
NeuronNotFound {
neuron_id: u64,
},
#[error("NNS Governance returned a neuron row without an id")]
MissingNeuronId,
#[error("invalid NNS neuron response: {reason}")]
InvalidResponse {
reason: String,
},
}
#[cfg(feature = "nns-host")]
#[derive(Debug, ThisError)]
pub enum NnsNeuronHostError {
#[error(transparent)]
Neuron(#[from] NnsNeuronError),
#[error(
"NNS neuron refresh stopped after {pages_fetched} pages and {rows_fetched} rows: {reason}"
)]
IncompleteRefresh {
pages_fetched: u32,
rows_fetched: usize,
reason: String,
},
#[error(
"cached NNS neuron snapshot identity mismatch at {}: {field} is {actual}, expected {expected}",
path.display()
)]
CacheIdentityMismatch {
path: PathBuf,
field: &'static str,
expected: String,
actual: String,
},
#[error("invalid NNS neuron cache at {}: {reason}", path.display())]
InvalidCache {
path: PathBuf,
reason: String,
},
#[error("invalid NNS neuron refresh attempt at {}: {reason}", path.display())]
InvalidRefreshAttempt {
path: PathBuf,
reason: String,
},
#[error(transparent)]
Cache(#[from] HostCacheError),
#[error(transparent)]
Runtime(#[from] RuntimeError),
}
#[cfg(feature = "nns-host")]
impl From<NnsGovernanceAttemptReadError> for NnsNeuronHostError {
fn from(error: NnsGovernanceAttemptReadError) -> Self {
match error {
NnsGovernanceAttemptReadError::Cache(error) => Self::Cache(error),
NnsGovernanceAttemptReadError::Invalid { path, reason } => {
Self::InvalidRefreshAttempt { path, reason }
}
}
}
}