Files
nym/sdk/rust/nym-sdk/src/error.rs
T
mfahampshire b231eb4f04 Max/asyncread asyncwrite nym client (#6318)
* Remove AsyncRead/Write traits from native client - moving them to
stream/

* Substream model first push

* Update / add examples

* Update lockfile

* Clippy

* clippy examples

* remove codecs

* Remove unused bincode setup

* Revert a lot of changes when SDK client itself implemented
AsyncRead/Write

* Remove unnecessary mut

* Use local PollSender in MixnetStream instead of client_input.input_sender

Now that client-core's input_sender is back to mpsc::Sender (reverted
PollSender migration), MixnetStream creates its own PollSender wrapper
for the AsyncWrite impl's poll_ready/start_send calls.

* Remove now-unnecessary parameter

* Clippy

* Cleanup more stragglers from previous setup (Async traits on
MixnetClient)

* Rename files (remove module inception)

* - Shrink StreamId from 16 bytes to u64, add version byte to wire format
  - Introduce MixStreamHeader/MixStreamFrame structs for decode
  - Replace StreamMap type alias with struct using tokio::sync::Mutex
  - Add StreamMap helper methods, eliminate lock().expect() panics
  - Rename stream.rs -> mixnet_stream.rs to avoid module inception
  - Document irrevocable stream mode, add LP integration TODO

* - Remove dummy channel
- Add err variant for reciever alredy taken
- Remove panics

* add timeout to stream

* clippy
2026-03-13 09:40:45 +00:00

122 lines
3.7 KiB
Rust

use nym_validator_client::nyxd::error::NyxdError;
use std::path::PathBuf;
/// Top-level Error enum for the mixnet client and its relevant types.
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("i/o error: {0}")]
IoError(#[from] std::io::Error),
#[error("toml serialization error: {0}")]
TomlSerializationError(#[from] toml::ser::Error),
#[error("toml deserialization error: {0}")]
TomlDeserializationError(#[from] toml::de::Error),
#[error("Ed25519 error: {0}")]
Ed25519RecoveryError(#[from] nym_crypto::asymmetric::ed25519::Ed25519RecoveryError),
#[error(transparent)]
ClientCoreError(#[from] nym_client_core::error::ClientCoreError),
#[error("key file encountered that we don't want to overwrite: {0}")]
DontOverwrite(PathBuf),
#[error("shared gateway key file encountered that we don't want to overwrite: {0}")]
DontOverwriteGatewayKey(PathBuf),
#[error("no gateway config available for writing")]
GatewayNotAvailableForWriting,
#[error("expected to received a directory, received: {0}")]
ExpectedDirectory(PathBuf),
#[error("failed to transition to registered state before connection to mixnet")]
FailedToTransitionToRegisteredState,
#[error(
"registering with gateway when the client is already in a registered state is not \
supported, and likely and user mistake"
)]
ReregisteringGatewayNotSupported,
#[error("no gateway key set")]
NoGatewayKeySet,
#[error("credentials mode not enabled")]
DisabledCredentialsMode,
#[error("bad validator details: {0}")]
BadValidatorDetails(#[from] NyxdError),
#[error("socks5 configuration set: {}, but expected to be {}", set, !set)]
Socks5Config { set: bool },
#[error("socks5 channel could not be started")]
Socks5NotStarted,
#[error("bandwidth controller error: {0}")]
BandwidthControllerError(#[from] nym_bandwidth_controller::error::BandwidthControllerError),
#[error("invalid voucher blob")]
InvalidVoucherBlob,
#[error("invalid mnemonic: {0}")]
InvalidMnemonic(#[from] bip39::Error),
#[error("failed to use reply storage backend: {source}")]
ReplyStorageError {
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("failed to use key storage backend: {source}")]
KeyStorageError {
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("failed to use credential storage backend: {source}")]
CredentialStorageError {
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error(transparent)]
CredentialIssuanceError {
#[from]
source: nym_credential_utils::Error,
},
#[error("loaded shared gateway key without providing information about what gateway it corresponds to")]
GatewayWithUnknownEndpoint,
#[error("failed to send the provided message")]
MessageSendingFailure,
#[error("this operation is currently unsupported: {details}")]
Unsupported { details: String },
#[error(transparent)]
Bincode(#[from] bincode::Error),
#[error("Failed to get shutdown tracker from the task runtime registry: {0}")]
RegistryAccess(#[from] nym_task::RegistryAccessError),
#[error("Cannot use message-based functions after stream mode is activated")]
StreamModeActive,
#[error("Stream listener has already been taken — listener() can only be called once")]
ListenerAlreadyTaken,
#[error("Stream subsystem failed to initialise: reconstructed_receiver unavailable")]
StreamInitFailure,
}
impl Error {
pub fn new_unsupported<S: Into<String>>(details: S) -> Self {
Error::Unsupported {
details: details.into(),
}
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;