iota_client/
error.rs

1// Copyright 2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error handling in iota-client crate.
5
6/// Type alias of `Result` in iota-client
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, thiserror::Error)]
10/// Error type of the iota client crate.
11#[allow(clippy::large_enum_variant)]
12pub enum Error {
13    /// Error when building indexation messages
14    #[error("Error when building indexation message: {0}")]
15    IndexationError(String),
16    /// Error when building transaction messages
17    #[error("Error when building transaction message")]
18    TransactionError,
19    /// The wallet account doesn't have enough balance
20    #[error("The wallet account doesn't have enough balance. It only has {0}, required is {1}")]
21    NotEnoughBalance(u64, u64),
22    /// The wallet account doesn't have enough balance
23    #[error(
24        "The wallet account has enough funds, but splitted on too many outputs: {0}, max. is 127, consolidate them"
25    )]
26    ConsolidationRequired(usize),
27    /// Dust error, for example not enough balance on an address
28    #[error("Dust error: {0}")]
29    DustError(String),
30    /// Missing required parameters
31    #[error("Must provide required parameter: {0}")]
32    MissingParameter(&'static str),
33    /// Invalid parameters
34    #[error("Parameter is invalid:{0}")]
35    InvalidParameter(&'static str),
36    /// No node available in the synced node pool
37    #[error("No synced node available")]
38    SyncedNodePoolEmpty,
39    /// Error on Url type conversion
40    #[error("Failed to parse node_pool_urls")]
41    NodePoolUrlsError,
42    /// Error on reaching quorum
43    #[error("Failed to reach quorum {0} {1}")]
44    QuorumThresholdError(usize, usize),
45    /// Error on quorum because not enough nodes are available
46    #[error("Not enough nodes for quorum {0} {1}")]
47    QuorumPoolSizeError(usize, usize),
48    /// Error on API request
49    #[error("Node error: {0}")]
50    NodeError(String),
51    /// Error on RwLock read
52    #[error("Failed to read node RwLock")]
53    NodeReadError,
54    /// Hex string convert error
55    #[error("{0}")]
56    FromHexError(#[from] hex::FromHexError),
57    /// Message types error
58    #[error("{0}")]
59    MessageError(#[from] bee_message::Error),
60    /// Bee rest api error
61    #[error("{0}")]
62    BeeRestApiError(#[from] bee_rest_api::types::error::Error),
63    /// The message doensn't need to be promoted or reattached
64    #[error("Message ID `{0}` doesn't need to be promoted or reattached")]
65    NoNeedPromoteOrReattach(String),
66    /// The message cannot be included into the Tangle
67    #[error("Message ID `{0}` couldn't get included into the Tangle")]
68    TangleInclusionError(String),
69    /// Mqtt client error
70    #[cfg(feature = "mqtt")]
71    #[error("{0}")]
72    MqttClientError(#[from] rumqttc::ClientError),
73    /// Invalid MQTT topic.
74    #[error("The MQTT topic {0} is invalid")]
75    InvalidMqttTopic(String),
76    /// MQTT connection not found (all nodes MQTT's are disabled)
77    #[error("MQTT connection not found (all nodes have the MQTT plugin disabled)")]
78    MqttConnectionNotFound,
79    /// IO error
80    #[error("{0}")]
81    IoError(#[from] std::io::Error),
82    /// JSON error
83    #[error("{0}")]
84    Json(#[from] serde_json::Error),
85    /// PoW error
86    #[error("{0}")]
87    Pow(String),
88    /// Address not found
89    #[error("Address: {0} not found in range: {1}")]
90    InputAddressNotFound(String, String),
91    /// Storage adapter not set_path
92    #[cfg(feature = "storage")]
93    #[error("Storage adapter not set {0}")]
94    StorageAdapterNotSet(String),
95    /// Storage error
96    #[cfg(feature = "storage")]
97    #[error("Storage error {0}")]
98    Storage(String),
99    /// Account not found error
100    #[cfg(feature = "storage")]
101    #[error("Account not found")]
102    AccountNotFound,
103    /// Crypto.rs error
104    #[error("{0}")]
105    CryptoError(#[from] crypto::Error),
106    /// Crypto.rs mnemonic error
107    #[error("{0}")]
108    MnemonicError(String),
109    /// Invalid amount of parents
110    #[error("Invalid amount of parents: {0}, length must be in 1..=8")]
111    InvalidParentsAmount(usize),
112    /// ureq error
113    #[cfg(feature = "sync")]
114    #[error("{0}")]
115    UreqError(Box<ureq::Error>),
116    /// Error from RestAPI calls with unexpected status code response
117    #[cfg(any(feature = "async", feature = "wasm"))]
118    #[error("Response error with status code {0}: {1}")]
119    ResponseError(u16, String),
120    /// reqwest error
121    #[cfg(any(feature = "async", feature = "wasm"))]
122    #[error("{0}")]
123    ReqwestError(#[from] reqwest::Error),
124    /// URL error
125    #[error("{0}")]
126    UrlError(#[from] url::ParseError),
127    /// URL validation error
128    #[error("{0}")]
129    UrlValidationError(String),
130    /// URL auth error
131    #[error("Can't set {0} to URL")]
132    UrlAuthError(String),
133    /// Blake2b256 Error
134    #[error("{0}")]
135    Blake2b256Error(&'static str),
136    /// Output Error
137    #[error("Output error: {0}")]
138    OutputError(&'static str),
139    #[cfg(not(feature = "wasm"))]
140    /// Tokio task join error
141    #[error("{0}")]
142    TaskJoinError(#[from] tokio::task::JoinError),
143    /// Invalid mnemonic error
144    #[error("Invalid mnemonic {0}")]
145    InvalidMnemonic(String),
146    /// PoW error
147    #[error("{0}")]
148    PowError(#[from] bee_pow::providers::miner::Error),
149    /// API error
150    #[error("Invalid API name")]
151    ApiError,
152    /// Rw lock failed.
153    #[error("Rw lock failed")]
154    PoisonError,
155}
156
157#[cfg(feature = "sync")]
158impl From<ureq::Error> for Error {
159    fn from(error: ureq::Error) -> Self {
160        Error::UreqError(Box::new(error))
161    }
162}