nym_sdk/
error.rs

1use nym_validator_client::nyxd::error::NyxdError;
2use std::path::PathBuf;
3
4/// Top-level Error enum for the mixnet client and its relevant types.
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("i/o error: {0}")]
8    IoError(#[from] std::io::Error),
9
10    #[error("toml serialization error: {0}")]
11    TomlSerializationError(#[from] toml::ser::Error),
12
13    #[error("toml deserialization error: {0}")]
14    TomlDeserializationError(#[from] toml::de::Error),
15
16    #[error("Ed25519 error: {0}")]
17    Ed25519RecoveryError(#[from] nym_crypto::asymmetric::ed25519::Ed25519RecoveryError),
18
19    #[error(transparent)]
20    ClientCoreError(#[from] nym_client_core::error::ClientCoreError),
21
22    #[error("key file encountered that we don't want to overwrite: {0}")]
23    DontOverwrite(PathBuf),
24
25    #[error("shared gateway key file encountered that we don't want to overwrite: {0}")]
26    DontOverwriteGatewayKey(PathBuf),
27
28    #[error("no gateway config available for writing")]
29    GatewayNotAvailableForWriting,
30
31    #[error("expected to received a directory, received: {0}")]
32    ExpectedDirectory(PathBuf),
33
34    #[error("failed to transition to registered state before connection to mixnet")]
35    FailedToTransitionToRegisteredState,
36
37    #[error(
38        "registering with gateway when the client is already in a registered state is not \
39         supported, and likely and user mistake"
40    )]
41    ReregisteringGatewayNotSupported,
42
43    #[error("no gateway key set")]
44    NoGatewayKeySet,
45
46    #[error("credentials mode not enabled")]
47    DisabledCredentialsMode,
48
49    #[error("bad validator details: {0}")]
50    BadValidatorDetails(#[from] NyxdError),
51
52    #[error("socks5 configuration set: {}, but expected to be {}", set, !set)]
53    Socks5Config { set: bool },
54
55    #[error("socks5 channel could not be started")]
56    Socks5NotStarted,
57
58    #[error("bandwidth controller error: {0}")]
59    BandwidthControllerError(#[from] nym_bandwidth_controller::error::BandwidthControllerError),
60
61    #[error("invalid voucher blob")]
62    InvalidVoucherBlob,
63
64    #[error("invalid mnemonic: {0}")]
65    InvalidMnemonic(#[from] bip39::Error),
66
67    #[error("failed to use reply storage backend: {source}")]
68    ReplyStorageError {
69        source: Box<dyn std::error::Error + Send + Sync>,
70    },
71
72    #[error("failed to use key storage backend: {source}")]
73    KeyStorageError {
74        source: Box<dyn std::error::Error + Send + Sync>,
75    },
76
77    #[error("failed to use credential storage backend: {source}")]
78    CredentialStorageError {
79        source: Box<dyn std::error::Error + Send + Sync>,
80    },
81
82    #[error(transparent)]
83    CredentialIssuanceError {
84        #[from]
85        source: nym_credential_utils::Error,
86    },
87
88    #[error("loaded shared gateway key without providing information about what gateway it corresponds to")]
89    GatewayWithUnknownEndpoint,
90
91    #[error("failed to send the provided message")]
92    MessageSendingFailure,
93
94    #[error("this operation is currently unsupported: {details}")]
95    Unsupported { details: String },
96
97    #[error(transparent)]
98    Bincode(#[from] bincode::Error),
99
100    #[error("Failed to get shutdown tracker from the task runtime registry: {0}")]
101    RegistryAccess(#[from] nym_task::RegistryAccessError),
102}
103
104impl Error {
105    pub fn new_unsupported<S: Into<String>>(details: S) -> Self {
106        Error::Unsupported {
107            details: details.into(),
108        }
109    }
110}
111
112pub type Result<T, E = Error> = std::result::Result<T, E>;