Skip to main content

nym_sdk_session/
error.rs

1// Copyright 2026 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use nym_validator_client::nym_api::error::NymAPIError;
5use nym_validator_client::nyxd::error::NyxdError;
6use std::net::SocketAddr;
7
8/// Errors produced while provisioning a dVPN session.
9#[derive(thiserror::Error, Debug)]
10pub enum SessionError {
11    /// Failed to construct or talk to the nyxd chain client.
12    #[error("nyxd chain client error: {0}")]
13    Nyxd(#[from] NyxdError),
14
15    /// A nym-api request failed.
16    #[error("nym-api error: {0}")]
17    Api(#[from] NymAPIError),
18
19    /// The configured network has no usable validator/API endpoint.
20    #[error("network details contain no usable {which} endpoint")]
21    MissingEndpoint { which: &'static str },
22
23    /// A URL in the network details could not be parsed.
24    #[error("invalid {which} url {url}: {source}")]
25    InvalidUrl {
26        which: &'static str,
27        url: String,
28        #[source]
29        source: url::ParseError,
30    },
31
32    /// Credential storage could not be opened.
33    #[error("credential storage error: {0}")]
34    Storage(String),
35
36    /// Ticketbook deposit / issuance failed.
37    #[error("ticketbook issuance error: {0}")]
38    Issuance(String),
39
40    /// Provisioning did not complete within its overall budget — most likely the ecash
41    /// signers / nym-apis are unresponsive. Any deposit already made is recorded in the
42    /// fetcher's pending-request store and is recovered (without re-depositing) on a retry.
43    #[error(
44        "provisioning timed out after {after:?} — the ecash signers are likely unresponsive; \
45         any deposit already made is recoverable from the pending-request store on retry"
46    )]
47    ProvisioningTimeout { after: std::time::Duration },
48
49    /// No gateway matched the requested identity.
50    #[error("no gateway found with identity {0}")]
51    GatewayNotFound(String),
52
53    /// No WireGuard-capable gateway is available for the requested role.
54    #[error("no WireGuard-capable gateway available for the requested role")]
55    NoWireguardGateway,
56
57    /// No WireGuard-capable gateway matched the requested country code.
58    #[error("no WireGuard-capable gateway found in country {0}")]
59    NoCountryMatch(String),
60
61    /// A QUIC-bridge entry gateway was required but none is available for the
62    /// requested selection (directory unavailable, or no QUIC gateway matches).
63    #[error("no QUIC-bridge gateway available for selection: {spec}")]
64    NoQuicGateway { spec: String },
65
66    #[error("entry and exit resolved to the same gateway ({0}); a two-hop tunnel needs distinct gateways")]
67    SameGatewaySelected(String),
68
69    /// A selected gateway advertised malformed LP data.
70    #[error("gateway {identity} advertised malformed LP data: {reason}")]
71    MalformedGateway { identity: String, reason: String },
72
73    /// Gateway registration failed.
74    #[error("registration with gateway at {address} failed: {source}")]
75    Registration {
76        address: SocketAddr,
77        #[source]
78        source: nym_registration_client::LpClientError,
79    },
80
81    /// The setup/issuance phase was cancelled via the CancellationToken.
82    #[error("session setup was cancelled")]
83    Cancelled,
84}