1use std::io;
8use std::str::Utf8Error;
9
10use inquire::InquireError;
11use rand::Error as RngError;
12
13use crate::gql::GraphQLError;
14
15#[derive(Debug, thiserror::Error)]
17pub enum Error {
18 #[error("This command cannot be performed while offline")]
20 Offline,
21 #[error("Unauthorized access to this address")]
23 Unauthorized,
24 #[error("Rusk error occurred: {0}")]
26 Rusk(String),
27 #[error(transparent)]
29 IO(#[from] io::Error),
30 #[error(transparent)]
32 Json(#[from] serde_json::Error),
33 #[error("A serialization error occurred: {0:?}")]
35 Bytes(dusk_bytes::Error),
36 #[error(transparent)]
38 Base58(#[from] bs58::decode::Error),
39 #[error("A serialization error occurred.")]
41 Rkyv,
42 #[error("Cannot create HTTP client")]
44 HttpClient,
45 #[error("A request error occurred: {0}")]
47 Reqwest(#[from] reqwest::Error),
48 #[error("Utf8 error: {0:?}")]
50 Utf8(Utf8Error),
51 #[error(transparent)]
53 Rng(#[from] RngError),
54 #[error("Insufficient balance to perform this operation")]
56 NotEnoughBalance,
57 #[error("Amount to transfer/stake cannot be zero")]
59 AmountIsZero,
60 #[error("Impossible notes' combination for the given value is")]
63 NoteCombinationProblem,
64 #[error("Note wasn't found in transfer-contract")]
66 NoteNotFound,
67 #[error("Note couldn't be decrypted with the provided ViewKey")]
69 WrongViewKey,
70 #[error("Not enough gas to perform this transaction")]
72 NotEnoughGas,
73 #[error("A stake does not exist for this key")]
75 NotStaked,
76 #[error("No reward available for this key")]
78 NoReward,
79 #[error("Invalid address")]
81 BadAddress,
82 #[error("Address does not belong to this wallet")]
84 AddressNotOwned,
85 #[error("No menu item selected")]
87 NoMenuItemSelected,
88 #[error("Invalid mnemonic phrase")]
90 InvalidMnemonicPhrase,
91 #[error("Path provided is not a directory")]
93 NotDirectory,
94 #[error("OS not supported")]
96 OsNotSupported,
97 #[error("Wallet file content is not valid")]
99 WalletFileCorrupted,
100 #[error("File version {0}.{1} not recognized")]
102 UnknownFileVersion(u8, u8),
103 #[error("A wallet file with this name already exists")]
105 WalletFileExists,
106 #[error("Wallet file is missing")]
108 WalletFileMissing,
109 #[error("Invalid password")]
111 BlockMode(#[from] block_modes::BlockModeError),
112 #[error("Reached the maximum number of attempts")]
114 AttemptsExhausted,
115 #[error("Status callback needs to be set before connecting")]
117 StatusWalletConnected,
118 #[error("Transaction error: {0}")]
120 Transaction(String),
121 #[error("Rocks cache database error: {0}")]
123 RocksDB(rocksdb::Error),
124 #[error(
126 "Network not found, check config.toml, specify network with -n flag"
127 )]
128 NetworkNotFound,
129 #[error("Cache database corrupted")]
131 CacheDatabaseCorrupted,
132 #[error("Prover Error: {0}")]
134 ProverError(String),
135 #[error("Memo too large {0}")]
137 MemoTooLarge(usize),
138 #[error("Expected BLS Public Key")]
140 ExpectedBlsPublicKey,
141 #[error("Expected Phoenix public Key")]
143 ExpectedPhoenixPublicKey,
144 #[error("Addresses use different transaction models")]
146 DifferentTransactionModels,
147 #[error("Invalid contractID provided")]
149 InvalidContractId,
150 #[error("Invalid WASM contract path provided")]
152 InvalidWasmContractPath,
153 #[error("Invalid environment variable value {0}")]
155 InvalidEnvVar(String),
156 #[error("Conversion error: {0}")]
158 Conversion(String),
159 #[error("GraphQL error: {0}")]
161 GraphQLError(GraphQLError),
162 #[error("Inquire error: {0}")]
164 InquireError(String),
165 #[error("Archive node query error: {0}")]
167 ArchiveJsonError(String),
168}
169
170impl From<dusk_bytes::Error> for Error {
171 fn from(e: dusk_bytes::Error) -> Self {
172 Self::Bytes(e)
173 }
174}
175
176impl From<block_modes::InvalidKeyIvLength> for Error {
177 fn from(_: block_modes::InvalidKeyIvLength) -> Self {
178 Self::WalletFileCorrupted
179 }
180}
181
182impl From<dusk_core::Error> for Error {
183 fn from(e: dusk_core::Error) -> Self {
184 use dusk_core::Error::*;
185
186 match e {
187 InsufficientBalance => Self::NotEnoughBalance,
188 Replay => Self::Transaction("Replay".to_string()),
189 PhoenixOwnership => Self::AddressNotOwned,
190 PhoenixCircuit(s) | PhoenixProver(s) => Self::ProverError(s),
191 InvalidData => Self::Bytes(dusk_bytes::Error::InvalidData),
192 BadLength(found, expected) => {
193 Self::Bytes(dusk_bytes::Error::BadLength { found, expected })
194 }
195 InvalidChar(ch, index) => {
196 Self::Bytes(dusk_bytes::Error::InvalidChar { ch, index })
197 }
198 Rkyv(_) => Self::Rkyv,
199 MemoTooLarge(m) => Self::MemoTooLarge(m),
200 }
201 }
202}
203
204impl From<rocksdb::Error> for Error {
205 fn from(e: rocksdb::Error) -> Self {
206 Self::RocksDB(e)
207 }
208}
209
210impl From<GraphQLError> for Error {
211 fn from(e: GraphQLError) -> Self {
212 Self::GraphQLError(e)
213 }
214}
215
216impl From<InquireError> for Error {
217 fn from(e: InquireError) -> Self {
218 Self::InquireError(e.to_string())
219 }
220}