nym_topology/
error.rs

1// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use std::array::TryFromSliceError;
5
6use crate::MixLayer;
7use nym_sphinx_addressing::NodeIdentity;
8use nym_sphinx_types::NymPacketError;
9use thiserror::Error;
10
11#[derive(Debug, Error)]
12pub enum NymTopologyError {
13    #[error(
14        "the provided network topology is empty - there are no valid nodes on it - the network request(s) probably failed"
15    )]
16    EmptyNetworkTopology,
17
18    #[error("no node with identity {node_identity} is known")]
19    NonExistentNode { node_identity: Box<NodeIdentity> },
20
21    #[error(
22        "could not use node with identity {node_identity} as egress since it didn't get assigned valid role in the current epoch"
23    )]
24    InvalidEgressRole { node_identity: Box<NodeIdentity> },
25
26    #[error("one (or more) of mixing layers does not have any valid nodes available")]
27    InsufficientMixingNodes,
28
29    #[error("The provided network topology has no gateways available")]
30    NoGatewaysAvailable,
31
32    #[error("The provided network topology has no valid mixnodes available")]
33    NoMixnodesAvailable,
34
35    #[error("Gateway with identity key {identity_key} doesn't exist")]
36    NonExistentGatewayError { identity_key: String },
37
38    #[error("timed out while waiting for gateway '{identity_key}' to come online")]
39    TimedOutWaitingForGateway { identity_key: String },
40
41    #[error(
42        "Wanted to create a mix route with {requested} hops, while only {available} layers are available"
43    )]
44    InvalidNumberOfHopsError { available: usize, requested: usize },
45
46    #[error("No mixnodes available on layer {layer}")]
47    EmptyMixLayer { layer: MixLayer },
48
49    #[error(
50        "Uneven layer distribution. Layer {layer} has {nodes} on it, while we expected a value between {lower_bound} and {upper_bound} as we have {total_nodes} nodes in total. Full breakdown: {layer_distribution:?}"
51    )]
52    UnevenLayerDistribution {
53        layer: MixLayer,
54        nodes: usize,
55        lower_bound: usize,
56        upper_bound: usize,
57        total_nodes: usize,
58        layer_distribution: Vec<(MixLayer, usize)>,
59    },
60    // We can't import SurbAckRecoveryError due to cyclic dependency, this is a bit dirty
61    #[error("Could not build payload")]
62    PayloadBuilder,
63
64    #[error("Outfox: {0}")]
65    Outfox(#[from] nym_sphinx_types::OutfoxError),
66
67    #[error("{0}")]
68    FromSlice(#[from] TryFromSliceError),
69
70    #[error("{0}")]
71    PacketError(#[from] NymPacketError),
72
73    #[error("{0}")]
74    ReqwestError(#[from] reqwest::Error),
75
76    #[error("{0}")]
77    VarError(#[from] std::env::VarError),
78}