use crate::nns::governance::{NnsGovernanceError, NnsGovernanceSourceProvenance};
#[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,
},
#[error("invalid NNS neuron collection page limit 0; expected at least one page")]
InvalidCollectionMaxPages,
#[error("invalid NNS neuron collection state: {reason}")]
InvalidCollectionState {
reason: String,
},
#[error(
"NNS neuron collection request changed {field}: received {actual}, expected {expected}"
)]
CollectionRequestMismatch {
field: &'static str,
expected: String,
actual: String,
},
#[error("NNS neuron collection is already complete after {pages_fetched} pages")]
CollectionComplete {
pages_fetched: u32,
},
#[error("NNS neuron collection reached its {max_pages}-page limit after {pages_fetched} pages")]
CollectionPageLimitReached {
pages_fetched: u32,
max_pages: u32,
},
#[error("NNS neuron collection source changed: received {actual:?}, expected {expected:?}")]
CollectionSourceChanged {
expected: NnsGovernanceSourceProvenance,
actual: NnsGovernanceSourceProvenance,
},
#[error("NNS neuron collection accounting overflow")]
CollectionAccountingOverflow,
}
#[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 }
}
}
}
}