nym_bandwidth_controller/
error.rs1use nym_credentials::error::Error as CredentialsError;
5use nym_validator_client::{coconut::EcashApiError, nym_api::EpochId};
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum BandwidthControllerError {
10 #[error("Nyxd error: {0}")]
11 Nyxd(#[from] nym_validator_client::nyxd::error::NyxdError),
12
13 #[error("coconut api query failure: {0}")]
14 CoconutApiError(#[from] EcashApiError),
15
16 #[error("There was a credential storage error - {0}")]
17 CredentialStorageError(Box<dyn std::error::Error + Send + Sync>),
18
19 #[error("a credential/global-data fetcher failed - {0}")]
20 FetcherError(Box<dyn std::error::Error + Send + Sync>),
21
22 #[error("No expiration date signatures for epoch : {epoch_id}")]
23 MissingExpirationDateSignatures { epoch_id: EpochId },
24
25 #[error("No coin index signatures for epoch : {epoch_id}")]
26 MissingCoinIndexSignatures { epoch_id: EpochId },
27
28 #[error("No verification key for epoch : {epoch_id}")]
29 MissingVerificationKey { epoch_id: EpochId },
30
31 #[error("retrieved upgrade mode token is not a valid String")]
32 MalformedUpgradeModeToken,
33
34 #[error("Credential error - {0}")]
35 CredentialError(#[from] CredentialsError),
36
37 #[error("internal error: {0}")]
39 Internal(String),
40
41 #[error("A channel we were using is closed")]
42 ChannelClosed,
43
44 #[error("Threshold not set yet")]
45 NoThreshold,
46
47 #[error("did not receive a valid response for aggregated data ({typ}) from ANY nym-api")]
48 ExhaustedApiQueries { typ: String },
49}
50
51impl BandwidthControllerError {
52 pub fn credential_storage_error(
53 source: impl std::error::Error + Send + Sync + 'static,
54 ) -> Self {
55 BandwidthControllerError::CredentialStorageError(Box::new(source))
56 }
57
58 pub fn fetcher_error(source: Box<dyn std::error::Error + Send + Sync>) -> Self {
59 BandwidthControllerError::FetcherError(source)
60 }
61
62 pub fn internal(message: impl ToString) -> Self {
63 BandwidthControllerError::Internal(message.to_string())
64 }
65}