nym_credential_utils/
errors.rs

1// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use nym_credential_storage::error::StorageError;
5use nym_credentials::error::Error as CredentialError;
6use nym_validator_client::coconut::EcashApiError;
7use nym_validator_client::nyxd::error::NyxdError;
8use std::num::ParseIntError;
9use thiserror::Error;
10
11pub type Result<T> = std::result::Result<T, Error>;
12
13#[derive(Error, Debug)]
14pub enum Error {
15    #[error(transparent)]
16    IOError(#[from] std::io::Error),
17
18    #[error(transparent)]
19    BandwidthControllerError(#[from] nym_bandwidth_controller::error::BandwidthControllerError),
20
21    #[error(transparent)]
22    EcashApiError(#[from] EcashApiError),
23
24    #[error(transparent)]
25    Nyxd(#[from] NyxdError),
26
27    #[error(transparent)]
28    Credential(#[from] CredentialError),
29
30    #[error("could not use shared storage: {0}")]
31    SharedStorageError(Box<dyn std::error::Error + Send + Sync>),
32
33    #[error("failed to parse credential value: {0}")]
34    MalformedCredentialValue(#[from] ParseIntError),
35}
36
37impl Error {
38    pub fn storage_error(source: impl std::error::Error + Send + Sync + 'static) -> Self {
39        Error::SharedStorageError(Box::new(source))
40    }
41}
42
43impl From<StorageError> for Error {
44    fn from(value: StorageError) -> Self {
45        Self::storage_error(value)
46    }
47}