error.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. // Hello developer. Please add your error to the according subsection
  19. // that is commented, or make a new subsection. Keep it clean.
  20. /// Main result type used throughout the codebase.
  21. pub type Result<T> = std::result::Result<T, Error>;
  22. /// Result type used in the Client module
  23. pub type ClientResult<T> = std::result::Result<T, ClientFailed>;
  24. /// General library errors used throughout the codebase.
  25. #[derive(Debug, Clone, thiserror::Error)]
  26. pub enum Error {
  27. // ==============
  28. // Parsing errors
  29. // ==============
  30. #[error("Parse failed: {0}")]
  31. ParseFailed(&'static str),
  32. #[error(transparent)]
  33. ParseIntError(#[from] std::num::ParseIntError),
  34. #[error(transparent)]
  35. ParseFloatError(#[from] std::num::ParseFloatError),
  36. #[cfg(feature = "url")]
  37. #[error(transparent)]
  38. UrlParseError(#[from] url::ParseError),
  39. #[error("URL parse error: {0}")]
  40. UrlParse(String),
  41. #[error(transparent)]
  42. AddrParseError(#[from] std::net::AddrParseError),
  43. #[error("Could not parse token parameter")]
  44. TokenParseError,
  45. #[error(transparent)]
  46. TryFromSliceError(#[from] std::array::TryFromSliceError),
  47. #[cfg(feature = "semver")]
  48. #[error("semver parse error: {0}")]
  49. SemverError(String),
  50. // ===============
  51. // Encoding errors
  52. // ===============
  53. #[error("decode failed: {0}")]
  54. DecodeError(&'static str),
  55. #[error("encode failed: {0}")]
  56. EncodeError(&'static str),
  57. #[error("VarInt was encoded in a non-minimal way")]
  58. NonMinimalVarInt,
  59. #[error(transparent)]
  60. Utf8Error(#[from] std::string::FromUtf8Error),
  61. #[error(transparent)]
  62. StrUtf8Error(#[from] std::str::Utf8Error),
  63. #[cfg(feature = "serde_json")]
  64. #[error("serde_json error: {0}")]
  65. SerdeJsonError(String),
  66. #[cfg(feature = "tinyjson")]
  67. #[error("JSON parse error: {0}")]
  68. JsonParseError(String),
  69. #[cfg(feature = "tinyjson")]
  70. #[error("JSON generate error: {0}")]
  71. JsonGenerateError(String),
  72. #[cfg(feature = "toml")]
  73. #[error(transparent)]
  74. TomlDeserializeError(#[from] toml::de::Error),
  75. #[cfg(feature = "bs58")]
  76. #[error(transparent)]
  77. Bs58DecodeError(#[from] bs58::decode::Error),
  78. #[error("Bad operation type byte")]
  79. BadOperationType,
  80. // ======================
  81. // Network-related errors
  82. // ======================
  83. #[error("Invalid Dialer scheme")]
  84. InvalidDialerScheme,
  85. #[error("Invalid Listener scheme")]
  86. InvalidListenerScheme,
  87. #[error("Unsupported network transport: {0}")]
  88. UnsupportedTransport(String),
  89. #[error("Unsupported network transport upgrade: {0}")]
  90. UnsupportedTransportUpgrade(String),
  91. #[error("Transport request exceeds number of accepted transports")]
  92. InvalidTransportRequest,
  93. #[error("Connection failed")]
  94. ConnectFailed,
  95. #[cfg(feature = "system")]
  96. #[error(transparent)]
  97. TimeoutError(#[from] crate::system::timeout::TimeoutError),
  98. #[error("Connection timed out")]
  99. ConnectTimeout,
  100. #[error("Channel stopped")]
  101. ChannelStopped,
  102. #[error("Channel timed out")]
  103. ChannelTimeout,
  104. #[error("Failed to reach any seeds")]
  105. SeedFailed,
  106. #[error("Network service stopped")]
  107. NetworkServiceStopped,
  108. #[error("Create listener bound to {0} failed")]
  109. BindFailed(String),
  110. #[error("Accept a new incoming connection from the listener {0} failed")]
  111. AcceptConnectionFailed(String),
  112. #[error("Accept a new tls connection from the listener {0} failed")]
  113. AcceptTlsConnectionFailed(String),
  114. #[error("Connector stopped")]
  115. ConnectorStopped,
  116. #[error("Network operation failed")]
  117. NetworkOperationFailed,
  118. #[error("Missing P2P message dispatcher")]
  119. MissingDispatcher,
  120. #[cfg(feature = "arti-client")]
  121. #[error(transparent)]
  122. ArtiError(#[from] arti_client::Error),
  123. #[error("Malformed packet")]
  124. MalformedPacket,
  125. #[error("Error decoding packet: {0}")]
  126. DecodePacket(String),
  127. #[error("Socks proxy error: {0}")]
  128. SocksError(String),
  129. #[error("No Socks5 URL found")]
  130. NoSocks5UrlFound,
  131. #[error("No URL found")]
  132. NoUrlFound,
  133. #[cfg(feature = "async-tungstenite")]
  134. #[error("tungstenite error: {0}")]
  135. TungsteniteError(String),
  136. #[error("Tor error: {0}")]
  137. TorError(String),
  138. #[error("Node is not connected to other nodes.")]
  139. NetworkNotConnected,
  140. #[error("P2P network stopped")]
  141. P2PNetworkStopped,
  142. #[error("No such host color exists")]
  143. InvalidHostColor,
  144. #[error("No matching hostlist entry")]
  145. HostDoesNotExist,
  146. #[error("Invalid state transition: current_state={0}, end_state={0}")]
  147. HostStateBlocked(String, String),
  148. // =============
  149. // Crypto errors
  150. // =============
  151. #[cfg(feature = "halo2_proofs")]
  152. #[error("halo2 plonk error: {0}")]
  153. PlonkError(String),
  154. #[error("Wrong witness type at index: {0}")]
  155. WrongWitnessType(usize),
  156. #[error("Wrong witnesses count")]
  157. WrongWitnessesCount,
  158. #[error("Wrong public inputs count")]
  159. WrongPublicInputsCount,
  160. #[error("Unable to decrypt mint note: {0}")]
  161. NoteDecryptionFailed(String),
  162. #[error("No keypair file detected")]
  163. KeypairPathNotFound,
  164. #[error("Failed converting bytes to PublicKey")]
  165. PublicKeyFromBytes,
  166. #[error("Failed converting bytes to Coin")]
  167. CoinFromBytes,
  168. #[error("Failed converting bytes to SecretKey")]
  169. SecretKeyFromBytes,
  170. #[error("Failed converting b58 string to PublicKey")]
  171. PublicKeyFromStr,
  172. #[error("Failed converting bs58 string to SecretKey")]
  173. SecretKeyFromStr,
  174. #[error("Invalid DarkFi address")]
  175. InvalidAddress,
  176. #[cfg(feature = "async-rustls")]
  177. #[error(transparent)]
  178. RustlsError(#[from] async_rustls::rustls::Error),
  179. #[cfg(feature = "async-rustls")]
  180. #[error("Invalid DNS Name {0}")]
  181. RustlsInvalidDns(String),
  182. #[error("unable to decrypt rcpt")]
  183. TxRcptDecryptionError,
  184. #[cfg(feature = "blake3")]
  185. #[error(transparent)]
  186. Blake3FromHexError(#[from] blake3::HexError),
  187. // =======================
  188. // Protocol-related errors
  189. // =======================
  190. #[error("Unsupported chain")]
  191. UnsupportedChain,
  192. #[error("JSON-RPC error: {0:?}")]
  193. JsonRpcError((i32, String)),
  194. #[cfg(feature = "rpc")]
  195. #[error(transparent)]
  196. RpcServerError(RpcError),
  197. #[cfg(feature = "rpc")]
  198. #[error("JSON-RPC connections exhausted")]
  199. RpcConnectionsExhausted,
  200. #[cfg(feature = "rpc")]
  201. #[error("JSON-RPC server stopped")]
  202. RpcServerStopped,
  203. #[cfg(feature = "rpc")]
  204. #[error("JSON-RPC client stopped")]
  205. RpcClientStopped,
  206. #[error("Unexpected JSON-RPC data received: {0}")]
  207. UnexpectedJsonRpc(String),
  208. #[error("Received proposal from unknown node")]
  209. UnknownNodeError,
  210. #[error("Public inputs are invalid")]
  211. InvalidPublicInputsError,
  212. #[error("Signature could not be verified")]
  213. InvalidSignature,
  214. #[error("State transition failed")]
  215. StateTransitionError,
  216. #[error("No forks exist")]
  217. ForksNotFound,
  218. #[error("Check if proposal extends any existing fork chains failed")]
  219. ExtendedChainIndexNotFound,
  220. #[error("Proposal contains missmatched hashes")]
  221. ProposalHashesMissmatchError,
  222. #[error("Proposal contains missmatched headers")]
  223. ProposalHeadersMissmatchError,
  224. #[error("Proposal contains more transactions than configured cap")]
  225. ProposalTxsExceedCapError,
  226. #[error("Unable to verify transfer transaction")]
  227. TransferTxVerification,
  228. #[error("Erroneous transactions detected")]
  229. ErroneousTxsDetected,
  230. #[error("Proposal task stopped")]
  231. ProposalTaskStopped,
  232. #[error("Proposal already exists")]
  233. ProposalAlreadyExists,
  234. #[error("Consensus task stopped")]
  235. ConsensusTaskStopped,
  236. #[error("Miner task stopped")]
  237. MinerTaskStopped,
  238. #[error("Garbage collection task stopped")]
  239. GarbageCollectionTaskStopped,
  240. #[error("Calculated total work is zero")]
  241. PoWTotalWorkIsZero,
  242. #[error("Erroneous cutoff calculation")]
  243. PoWCuttofCalculationError,
  244. #[error("Provided timestamp is invalid")]
  245. PoWInvalidTimestamp,
  246. #[error("Provided output hash is greater than current target")]
  247. PoWInvalidOutHash,
  248. // ===============
  249. // Database errors
  250. // ===============
  251. #[cfg(feature = "rusqlite")]
  252. #[error("rusqlite error: {0}")]
  253. RusqliteError(String),
  254. #[cfg(feature = "sled")]
  255. #[error(transparent)]
  256. SledError(#[from] sled::Error),
  257. #[cfg(feature = "sled")]
  258. #[error(transparent)]
  259. SledTransactionError(#[from] sled::transaction::TransactionError),
  260. #[error("Transaction {0} not found in database")]
  261. TransactionNotFound(String),
  262. #[error("Transaction already seen")]
  263. TransactionAlreadySeen,
  264. #[error("Input vectors have different length")]
  265. InvalidInputLengths,
  266. #[error("Header {0} not found in database")]
  267. HeaderNotFound(String),
  268. #[error("Block {0} is invalid")]
  269. BlockIsInvalid(String),
  270. #[error("Block version {0} is invalid")]
  271. BlockVersionIsInvalid(u8),
  272. #[error("Block {0} already in database")]
  273. BlockAlreadyExists(String),
  274. #[error("Block {0} not found in database")]
  275. BlockNotFound(String),
  276. #[error("Block with height number {0} not found in database")]
  277. BlockHeightNotFound(u32),
  278. #[error("Block difficulty for height number {0} not found in database")]
  279. BlockDifficultyNotFound(u32),
  280. #[error("Block {0} contains 0 transactions")]
  281. BlockContainsNoTransactions(String),
  282. #[error("Contract {0} not found in database")]
  283. ContractNotFound(String),
  284. #[error("Contract state tree not found")]
  285. ContractStateNotFound,
  286. #[error("Contract already initialized")]
  287. ContractAlreadyInitialized,
  288. #[error("zkas bincode not found in sled database")]
  289. ZkasBincodeNotFound,
  290. // ===================
  291. // wasm runtime errors
  292. // ===================
  293. #[cfg(feature = "wasm-runtime")]
  294. #[error("Wasmer compile error: {0}")]
  295. WasmerCompileError(String),
  296. #[cfg(feature = "wasm-runtime")]
  297. #[error("Wasmer export error: {0}")]
  298. WasmerExportError(String),
  299. #[cfg(feature = "wasm-runtime")]
  300. #[error("Wasmer runtime error: {0}")]
  301. WasmerRuntimeError(String),
  302. #[cfg(feature = "wasm-runtime")]
  303. #[error("Wasmer instantiation error: {0}")]
  304. WasmerInstantiationError(String),
  305. #[cfg(feature = "wasm-runtime")]
  306. #[error("wasm memory error")]
  307. WasmerMemoryError(String),
  308. #[cfg(feature = "wasm-runtime")]
  309. #[error("wasm runtime out of memory")]
  310. WasmerOomError(String),
  311. #[cfg(feature = "darkfi-sdk")]
  312. #[error("Contract execution failed: {0}")]
  313. ContractError(darkfi_sdk::error::ContractError),
  314. #[cfg(feature = "darkfi-sdk")]
  315. #[error("Invalid DarkTree: {0}")]
  316. DarkTreeError(darkfi_sdk::error::DarkTreeError),
  317. #[cfg(feature = "blockchain")]
  318. #[error("contract wasm bincode not found")]
  319. WasmBincodeNotFound,
  320. #[cfg(feature = "wasm-runtime")]
  321. #[error("contract initialize error")]
  322. ContractInitError(u64),
  323. #[cfg(feature = "wasm-runtime")]
  324. #[error("contract execution error")]
  325. ContractExecError(u64),
  326. #[cfg(feature = "wasm-runtime")]
  327. #[error("wasm function ACL denied")]
  328. WasmFunctionAclDenied,
  329. // ====================
  330. // Event Graph errors
  331. // ====================
  332. #[error("Event is not found in tree: {0}")]
  333. EventNotFound(String),
  334. #[error("Event is invalid")]
  335. EventIsInvalid,
  336. // ====================
  337. // Miscellaneous errors
  338. // ====================
  339. #[error("IO error: {0}")]
  340. Io(std::io::ErrorKind),
  341. #[error("Infallible error: {0}")]
  342. InfallibleError(String),
  343. #[cfg(feature = "smol")]
  344. #[error("async_channel sender error: {0}")]
  345. AsyncChannelSendError(String),
  346. #[cfg(feature = "smol")]
  347. #[error("async_channel receiver error: {0}")]
  348. AsyncChannelRecvError(String),
  349. #[error("SetLogger (log crate) failed: {0}")]
  350. SetLoggerError(String),
  351. #[error("ValueIsNotObject")]
  352. ValueIsNotObject,
  353. #[error("No config file detected")]
  354. ConfigNotFound,
  355. #[error("Invalid config file detected")]
  356. ConfigInvalid,
  357. #[error("Failed decoding bincode: {0}")]
  358. ZkasDecoderError(String),
  359. #[cfg(feature = "util")]
  360. #[error("System clock is not correct!")]
  361. InvalidClock,
  362. #[error("Unsupported OS")]
  363. UnsupportedOS,
  364. #[error("System clock went backwards")]
  365. BackwardsTime(std::time::SystemTimeError),
  366. #[error("Detached task stopped")]
  367. DetachedTaskStopped,
  368. #[error("Addition overflow")]
  369. AdditionOverflow,
  370. #[error("Subtraction underflow")]
  371. SubtractionUnderflow,
  372. // ==============================================
  373. // Wrappers for other error types in this library
  374. // ==============================================
  375. #[error(transparent)]
  376. ClientFailed(#[from] ClientFailed),
  377. #[cfg(feature = "tx")]
  378. #[error(transparent)]
  379. TxVerifyFailed(#[from] TxVerifyFailed),
  380. //=============
  381. // clock
  382. //=============
  383. #[error("clock out of sync with peers: {0}")]
  384. ClockOutOfSync(String),
  385. // ================
  386. // DHT/Geode errors
  387. // ================
  388. #[error("Geode needs garbage collection")]
  389. GeodeNeedsGc,
  390. #[error("Geode file not found")]
  391. GeodeFileNotFound,
  392. #[error("Geode chunk not found")]
  393. GeodeChunkNotFound,
  394. #[error("Geode file route not found")]
  395. GeodeFileRouteNotFound,
  396. #[error("Geode chunk route not found")]
  397. GeodeChunkRouteNotFound,
  398. // ==================
  399. // Event Graph errors
  400. // ==================
  401. #[error("DAG sync failed")]
  402. DagSyncFailed,
  403. // =========
  404. // Catch-all
  405. // =========
  406. #[error("{0}")]
  407. Custom(String),
  408. }
  409. #[cfg(feature = "tx")]
  410. impl Error {
  411. /// Auxiliary function to retrieve the vector of erroneous
  412. /// transactions from a TxVerifyFailed error.
  413. /// In any other case, we return the error itself.
  414. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  415. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  416. return Ok(erroneous_txs.clone())
  417. };
  418. Err(self.clone())
  419. }
  420. }
  421. #[cfg(feature = "tx")]
  422. /// Transaction verification errors
  423. #[derive(Debug, Clone, thiserror::Error)]
  424. pub enum TxVerifyFailed {
  425. #[error("Transaction {0} already exists")]
  426. AlreadySeenTx(String),
  427. #[error("Invalid transaction signature")]
  428. InvalidSignature,
  429. #[error("Missing signatures in transaction")]
  430. MissingSignatures,
  431. #[error("Missing contract calls in transaction")]
  432. MissingCalls,
  433. #[error("Invalid ZK proof in transaction")]
  434. InvalidZkProof,
  435. #[error("Missing Money::Fee call in transaction")]
  436. MissingFee,
  437. #[error("Invalid Money::Fee call in transaction")]
  438. InvalidFee,
  439. #[error("Insufficient fee paid")]
  440. InsufficientFee,
  441. #[error("Erroneous transactions found")]
  442. ErroneousTxs(Vec<crate::tx::Transaction>),
  443. }
  444. /// Client module errors
  445. #[derive(Debug, Clone, thiserror::Error)]
  446. pub enum ClientFailed {
  447. #[error("IO error: {0}")]
  448. Io(std::io::ErrorKind),
  449. #[error("Not enough value: {0}")]
  450. NotEnoughValue(u64),
  451. #[error("Invalid address: {0}")]
  452. InvalidAddress(String),
  453. #[error("Invalid amount: {0}")]
  454. InvalidAmount(u64),
  455. #[error("Invalid token ID: {0}")]
  456. InvalidTokenId(String),
  457. #[error("Internal error: {0}")]
  458. InternalError(String),
  459. #[error("Verify error: {0}")]
  460. VerifyError(String),
  461. }
  462. #[cfg(feature = "rpc")]
  463. #[derive(Clone, Debug, thiserror::Error)]
  464. pub enum RpcError {
  465. #[error("Connection closed: {0}")]
  466. ConnectionClosed(String),
  467. #[error("Invalid JSON: {0}")]
  468. InvalidJson(String),
  469. #[error("IO Error: {0}")]
  470. IoError(std::io::ErrorKind),
  471. }
  472. #[cfg(feature = "rpc")]
  473. impl From<std::io::Error> for RpcError {
  474. fn from(err: std::io::Error) -> Self {
  475. Self::IoError(err.kind())
  476. }
  477. }
  478. #[cfg(feature = "rpc")]
  479. impl From<RpcError> for Error {
  480. fn from(err: RpcError) -> Self {
  481. Self::RpcServerError(err)
  482. }
  483. }
  484. impl From<Error> for ClientFailed {
  485. fn from(err: Error) -> Self {
  486. Self::InternalError(err.to_string())
  487. }
  488. }
  489. impl From<std::io::Error> for ClientFailed {
  490. fn from(err: std::io::Error) -> Self {
  491. Self::Io(err.kind())
  492. }
  493. }
  494. impl From<std::io::Error> for Error {
  495. fn from(err: std::io::Error) -> Self {
  496. Self::Io(err.kind())
  497. }
  498. }
  499. impl From<std::time::SystemTimeError> for Error {
  500. fn from(err: std::time::SystemTimeError) -> Self {
  501. Self::BackwardsTime(err)
  502. }
  503. }
  504. impl From<std::convert::Infallible> for Error {
  505. fn from(err: std::convert::Infallible) -> Self {
  506. Self::InfallibleError(err.to_string())
  507. }
  508. }
  509. impl From<()> for Error {
  510. fn from(_err: ()) -> Self {
  511. Self::InfallibleError("Infallible".into())
  512. }
  513. }
  514. #[cfg(feature = "net")]
  515. impl From<std::collections::TryReserveError> for Error {
  516. fn from(err: std::collections::TryReserveError) -> Self {
  517. Self::DecodePacket(err.to_string())
  518. }
  519. }
  520. #[cfg(feature = "smol")]
  521. impl<T> From<smol::channel::SendError<T>> for Error {
  522. fn from(err: smol::channel::SendError<T>) -> Self {
  523. Self::AsyncChannelSendError(err.to_string())
  524. }
  525. }
  526. #[cfg(feature = "smol")]
  527. impl From<smol::channel::RecvError> for Error {
  528. fn from(err: smol::channel::RecvError) -> Self {
  529. Self::AsyncChannelRecvError(err.to_string())
  530. }
  531. }
  532. impl From<log::SetLoggerError> for Error {
  533. fn from(err: log::SetLoggerError) -> Self {
  534. Self::SetLoggerError(err.to_string())
  535. }
  536. }
  537. #[cfg(feature = "rusqlite")]
  538. impl From<rusqlite::Error> for Error {
  539. fn from(err: rusqlite::Error) -> Self {
  540. Self::RusqliteError(err.to_string())
  541. }
  542. }
  543. #[cfg(feature = "halo2_proofs")]
  544. impl From<halo2_proofs::plonk::Error> for Error {
  545. fn from(err: halo2_proofs::plonk::Error) -> Self {
  546. Self::PlonkError(err.to_string())
  547. }
  548. }
  549. #[cfg(feature = "semver")]
  550. impl From<semver::Error> for Error {
  551. fn from(err: semver::Error) -> Self {
  552. Self::SemverError(err.to_string())
  553. }
  554. }
  555. /*
  556. #[cfg(feature = "tungstenite")]
  557. impl From<tungstenite::Error> for Error {
  558. fn from(err: tungstenite::Error) -> Self {
  559. Self::TungsteniteError(err.to_string())
  560. }
  561. }
  562. */
  563. #[cfg(feature = "async-tungstenite")]
  564. impl From<async_tungstenite::tungstenite::Error> for Error {
  565. fn from(err: async_tungstenite::tungstenite::Error) -> Self {
  566. Self::TungsteniteError(err.to_string())
  567. }
  568. }
  569. #[cfg(feature = "async-rustls")]
  570. impl From<async_rustls::rustls::client::InvalidDnsNameError> for Error {
  571. fn from(err: async_rustls::rustls::client::InvalidDnsNameError) -> Self {
  572. Self::RustlsInvalidDns(err.to_string())
  573. }
  574. }
  575. #[cfg(feature = "serde_json")]
  576. impl From<serde_json::Error> for Error {
  577. fn from(err: serde_json::Error) -> Self {
  578. Self::SerdeJsonError(err.to_string())
  579. }
  580. }
  581. #[cfg(feature = "tinyjson")]
  582. impl From<tinyjson::JsonParseError> for Error {
  583. fn from(err: tinyjson::JsonParseError) -> Self {
  584. Self::JsonParseError(err.to_string())
  585. }
  586. }
  587. #[cfg(feature = "tinyjson")]
  588. impl From<tinyjson::JsonGenerateError> for Error {
  589. fn from(err: tinyjson::JsonGenerateError) -> Self {
  590. Self::JsonGenerateError(err.to_string())
  591. }
  592. }
  593. #[cfg(feature = "fast-socks5")]
  594. impl From<fast_socks5::SocksError> for Error {
  595. fn from(err: fast_socks5::SocksError) -> Self {
  596. Self::SocksError(err.to_string())
  597. }
  598. }
  599. #[cfg(feature = "wasm-runtime")]
  600. impl From<wasmer::CompileError> for Error {
  601. fn from(err: wasmer::CompileError) -> Self {
  602. Self::WasmerCompileError(err.to_string())
  603. }
  604. }
  605. #[cfg(feature = "wasm-runtime")]
  606. impl From<wasmer::ExportError> for Error {
  607. fn from(err: wasmer::ExportError) -> Self {
  608. Self::WasmerExportError(err.to_string())
  609. }
  610. }
  611. #[cfg(feature = "wasm-runtime")]
  612. impl From<wasmer::RuntimeError> for Error {
  613. fn from(err: wasmer::RuntimeError) -> Self {
  614. Self::WasmerRuntimeError(err.to_string())
  615. }
  616. }
  617. #[cfg(feature = "wasm-runtime")]
  618. impl From<wasmer::InstantiationError> for Error {
  619. fn from(err: wasmer::InstantiationError) -> Self {
  620. Self::WasmerInstantiationError(err.to_string())
  621. }
  622. }
  623. #[cfg(feature = "wasm-runtime")]
  624. impl From<wasmer::MemoryAccessError> for Error {
  625. fn from(err: wasmer::MemoryAccessError) -> Self {
  626. Self::WasmerMemoryError(err.to_string())
  627. }
  628. }
  629. #[cfg(feature = "wasm-runtime")]
  630. impl From<wasmer::MemoryError> for Error {
  631. fn from(err: wasmer::MemoryError) -> Self {
  632. Self::WasmerOomError(err.to_string())
  633. }
  634. }
  635. #[cfg(feature = "darkfi-sdk")]
  636. impl From<darkfi_sdk::error::ContractError> for Error {
  637. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  638. Self::ContractError(err)
  639. }
  640. }
  641. #[cfg(feature = "darkfi-sdk")]
  642. impl From<darkfi_sdk::error::DarkTreeError> for Error {
  643. fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
  644. Self::DarkTreeError(err)
  645. }
  646. }