error.rs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 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 = "dashu")]
  48. #[error(transparent)]
  49. DashuConversionError(#[from] dashu::base::error::ConversionError),
  50. #[cfg(feature = "dashu")]
  51. #[error(transparent)]
  52. DashuParseError(#[from] dashu::base::error::ParseError),
  53. #[cfg(feature = "semver")]
  54. #[error("semver parse error: {0}")]
  55. SemverError(String),
  56. // ===============
  57. // Encoding errors
  58. // ===============
  59. #[error("decode failed: {0}")]
  60. DecodeError(&'static str),
  61. #[error("encode failed: {0}")]
  62. EncodeError(&'static str),
  63. #[error("VarInt was encoded in a non-minimal way")]
  64. NonMinimalVarInt,
  65. #[error(transparent)]
  66. Utf8Error(#[from] std::string::FromUtf8Error),
  67. #[error(transparent)]
  68. StrUtf8Error(#[from] std::str::Utf8Error),
  69. #[cfg(feature = "serde_json")]
  70. #[error("serde_json error: {0}")]
  71. SerdeJsonError(String),
  72. #[cfg(feature = "tinyjson")]
  73. #[error("JSON parse error: {0}")]
  74. JsonParseError(String),
  75. #[cfg(feature = "tinyjson")]
  76. #[error("JSON generate error: {0}")]
  77. JsonGenerateError(String),
  78. #[cfg(feature = "toml")]
  79. #[error(transparent)]
  80. TomlDeserializeError(#[from] toml::de::Error),
  81. #[cfg(feature = "bs58")]
  82. #[error(transparent)]
  83. Bs58DecodeError(#[from] bs58::decode::Error),
  84. #[error("Bad operation type byte")]
  85. BadOperationType,
  86. // ======================
  87. // Network-related errors
  88. // ======================
  89. #[error("Invalid Dialer scheme")]
  90. InvalidDialerScheme,
  91. #[error("Invalid Listener scheme")]
  92. InvalidListenerScheme,
  93. #[error("Unsupported network transport: {0}")]
  94. UnsupportedTransport(String),
  95. #[error("Unsupported network transport upgrade: {0}")]
  96. UnsupportedTransportUpgrade(String),
  97. #[error("Connection failed")]
  98. ConnectFailed,
  99. #[cfg(feature = "system")]
  100. #[error(transparent)]
  101. TimeoutError(#[from] crate::system::timeout::TimeoutError),
  102. #[error("Connection timed out")]
  103. ConnectTimeout,
  104. #[error("Channel stopped")]
  105. ChannelStopped,
  106. #[error("Channel timed out")]
  107. ChannelTimeout,
  108. #[error("Failed to reach any seeds")]
  109. SeedFailed,
  110. #[error("Network service stopped")]
  111. NetworkServiceStopped,
  112. #[error("Create listener bound to {0} failed")]
  113. BindFailed(String),
  114. #[error("Accept a new incoming connection from the listener {0} failed")]
  115. AcceptConnectionFailed(String),
  116. #[error("Accept a new tls connection from the listener {0} failed")]
  117. AcceptTlsConnectionFailed(String),
  118. #[error("Network operation failed")]
  119. NetworkOperationFailed,
  120. #[error("Missing P2P message dispatcher")]
  121. MissingDispatcher,
  122. #[cfg(feature = "arti-client")]
  123. #[error(transparent)]
  124. ArtiError(#[from] arti_client::Error),
  125. #[error("Malformed packet")]
  126. MalformedPacket,
  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 matching hostlist entry")]
  143. HostDoesNotExist,
  144. // =============
  145. // Crypto errors
  146. // =============
  147. #[cfg(feature = "halo2_proofs")]
  148. #[error("halo2 plonk error: {0}")]
  149. PlonkError(String),
  150. #[error("Wrong witness type at index: {0}")]
  151. WrongWitnessType(usize),
  152. #[error("Wrong witnesses count")]
  153. WrongWitnessesCount,
  154. #[error("Wrong public inputs count")]
  155. WrongPublicInputsCount,
  156. #[error("Unable to decrypt mint note: {0}")]
  157. NoteDecryptionFailed(String),
  158. #[error("No keypair file detected")]
  159. KeypairPathNotFound,
  160. #[error("Failed converting bytes to PublicKey")]
  161. PublicKeyFromBytes,
  162. #[error("Failed converting bytes to Coin")]
  163. CoinFromBytes,
  164. #[error("Failed converting bytes to SecretKey")]
  165. SecretKeyFromBytes,
  166. #[error("Failed converting b58 string to PublicKey")]
  167. PublicKeyFromStr,
  168. #[error("Failed converting bs58 string to SecretKey")]
  169. SecretKeyFromStr,
  170. #[error("Invalid DarkFi address")]
  171. InvalidAddress,
  172. #[cfg(feature = "async-rustls")]
  173. #[error(transparent)]
  174. RustlsError(#[from] async_rustls::rustls::Error),
  175. #[cfg(feature = "async-rustls")]
  176. #[error("Invalid DNS Name {0}")]
  177. RustlsInvalidDns(String),
  178. #[error("unable to decrypt rcpt")]
  179. TxRcptDecryptionError,
  180. #[cfg(feature = "blake3")]
  181. #[error(transparent)]
  182. Blake3FromHexError(#[from] blake3::HexError),
  183. // =======================
  184. // Protocol-related errors
  185. // =======================
  186. #[error("Unsupported chain")]
  187. UnsupportedChain,
  188. #[error("JSON-RPC error: {0:?}")]
  189. JsonRpcError((i32, String)),
  190. #[cfg(feature = "rpc")]
  191. #[error(transparent)]
  192. RpcServerError(RpcError),
  193. #[cfg(feature = "rpc")]
  194. #[error("JSON-RPC connections exhausted")]
  195. RpcConnectionsExhausted,
  196. #[cfg(feature = "rpc")]
  197. #[error("JSON-RPC server stopped")]
  198. RpcServerStopped,
  199. #[cfg(feature = "rpc")]
  200. #[error("JSON-RPC client stopped")]
  201. RpcClientStopped,
  202. #[error("Unexpected JSON-RPC data received: {0}")]
  203. UnexpectedJsonRpc(String),
  204. #[error("Received proposal from unknown node")]
  205. UnknownNodeError,
  206. #[error("Public inputs are invalid")]
  207. InvalidPublicInputsError,
  208. #[error("Coin is not the slot block producer")]
  209. CoinIsNotSlotProducer,
  210. #[error("Error during leader proof verification")]
  211. LeaderProofVerification,
  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 received after finalization sync period")]
  221. ProposalAfterFinalizationError,
  222. #[error("Proposal received not for current slot")]
  223. ProposalNotForCurrentSlotError,
  224. #[error("Proposal contains missmatched hashes")]
  225. ProposalHashesMissmatchError,
  226. #[error("Proposal contains unknown slots")]
  227. ProposalContainsUnknownSlots,
  228. #[error("Proposal contains missmatched headers")]
  229. ProposalHeadersMissmatchError,
  230. #[error("Proposal contains different coin creation eta")]
  231. ProposalDifferentCoinEtaError,
  232. #[error("Proposal contains spent coin")]
  233. ProposalIsSpent,
  234. #[error("Proposal contains more transactions than configured cap")]
  235. ProposalTxsExceedCapError,
  236. #[error("Unable to verify transfer transaction")]
  237. TransferTxVerification,
  238. #[error("Unable to verify proposed mu values")]
  239. ProposalPublicValuesMismatched,
  240. #[error("Proposer is not eligible to produce proposals")]
  241. ProposalProposerNotEligible,
  242. #[error("Erroneous transactions detected")]
  243. ErroneousTxsDetected,
  244. #[error("Proposal task stopped")]
  245. ProposalTaskStopped,
  246. #[error("Proposal already exists")]
  247. ProposalAlreadyExists,
  248. #[error("Miner task stopped")]
  249. MinerTaskStopped,
  250. #[error("Calculated total work is zero")]
  251. PoWTotalWorkIsZero,
  252. #[error("Erroneous cutoff calculation")]
  253. PoWCuttofCalculationError,
  254. #[error("Provided timestamp is invalid")]
  255. PoWInvalidTimestamp,
  256. #[error("Provided output hash is greater than current target")]
  257. PoWInvalidOutHash,
  258. // ===============
  259. // Database errors
  260. // ===============
  261. #[cfg(feature = "rusqlite")]
  262. #[error("rusqlite error: {0}")]
  263. RusqliteError(String),
  264. #[cfg(feature = "sled")]
  265. #[error(transparent)]
  266. SledError(#[from] sled::Error),
  267. #[cfg(feature = "sled")]
  268. #[error(transparent)]
  269. SledTransactionError(#[from] sled::transaction::TransactionError),
  270. #[error("Transaction {0} not found in database")]
  271. TransactionNotFound(String),
  272. #[error("Transaction already seen")]
  273. TransactionAlreadySeen,
  274. #[error("Input vectors have different length")]
  275. InvalidInputLengths,
  276. #[error("Header {0} not found in database")]
  277. HeaderNotFound(String),
  278. #[error("Block {0} is invalid")]
  279. BlockIsInvalid(String),
  280. #[error("Block version {0} is invalid")]
  281. BlockVersionIsInvalid(u8),
  282. #[error("Block {0} already in database")]
  283. BlockAlreadyExists(String),
  284. #[error("Block {0} not found in database")]
  285. BlockNotFound(String),
  286. #[error("Block with order number {0} not found in database")]
  287. BlockNumberNotFound(u64),
  288. #[error("Block difficulty for height number {0} not found in database")]
  289. BlockDifficultyNotFound(u64),
  290. #[error("Block {0} contains 0 transactions")]
  291. BlockContainsNoTransactions(String),
  292. #[error("Verifying slot missmatch")]
  293. VerifyingSlotMissmatch(),
  294. #[error("Slot {0} is invalid")]
  295. SlotIsInvalid(u64),
  296. #[error("Slot {0} not found in database")]
  297. SlotNotFound(u64),
  298. #[error("Block {0} slots not found in database")]
  299. BlockSlotsNotFound(String),
  300. #[error("Future slot {0} was received")]
  301. FutureSlotReceived(u64),
  302. #[error("Contract {0} not found in database")]
  303. ContractNotFound(String),
  304. #[error("Contract state tree not found")]
  305. ContractStateNotFound,
  306. #[error("Contract already initialized")]
  307. ContractAlreadyInitialized,
  308. #[error("zkas bincode not found in sled database")]
  309. ZkasBincodeNotFound,
  310. // =============
  311. // Wallet errors
  312. // =============
  313. #[error("Wallet password is empty")]
  314. WalletEmptyPassword,
  315. #[error("Merkle tree already exists in wallet")]
  316. WalletTreeExists,
  317. #[error("Wallet insufficient balance")]
  318. WalletInsufficientBalance,
  319. // ===================
  320. // wasm runtime errors
  321. // ===================
  322. #[cfg(feature = "wasm-runtime")]
  323. #[error("Wasmer compile error: {0}")]
  324. WasmerCompileError(String),
  325. #[cfg(feature = "wasm-runtime")]
  326. #[error("Wasmer export error: {0}")]
  327. WasmerExportError(String),
  328. #[cfg(feature = "wasm-runtime")]
  329. #[error("Wasmer runtime error: {0}")]
  330. WasmerRuntimeError(String),
  331. #[cfg(feature = "wasm-runtime")]
  332. #[error("Wasmer instantiation error: {0}")]
  333. WasmerInstantiationError(String),
  334. #[cfg(feature = "wasm-runtime")]
  335. #[error("wasm memory error")]
  336. WasmerMemoryError(String),
  337. #[cfg(feature = "wasm-runtime")]
  338. #[error("wasm runtime out of memory")]
  339. WasmerOomError(String),
  340. #[cfg(feature = "darkfi-sdk")]
  341. #[error("Contract execution failed: {0}")]
  342. ContractError(darkfi_sdk::error::ContractError),
  343. #[cfg(feature = "darkfi-sdk")]
  344. #[error("Invalid DarkTree: {0}")]
  345. DarkTreeError(darkfi_sdk::error::DarkTreeError),
  346. #[cfg(feature = "blockchain")]
  347. #[error("contract wasm bincode not found")]
  348. WasmBincodeNotFound,
  349. #[cfg(feature = "wasm-runtime")]
  350. #[error("contract initialize error")]
  351. ContractInitError(u64),
  352. #[cfg(feature = "wasm-runtime")]
  353. #[error("contract execution error")]
  354. ContractExecError(u64),
  355. #[cfg(feature = "wasm-runtime")]
  356. #[error("wasm function ACL denied")]
  357. WasmFunctionAclDenied,
  358. // ====================
  359. // Event Graph errors
  360. // ====================
  361. #[error("Event is not found in tree: {0}")]
  362. EventNotFound(String),
  363. #[error("Event is invalid")]
  364. EventIsInvalid,
  365. // ====================
  366. // Miscellaneous errors
  367. // ====================
  368. #[error("IO error: {0}")]
  369. Io(std::io::ErrorKind),
  370. #[error("Infallible error: {0}")]
  371. InfallibleError(String),
  372. #[cfg(feature = "smol")]
  373. #[error("async_channel sender error: {0}")]
  374. AsyncChannelSendError(String),
  375. #[cfg(feature = "smol")]
  376. #[error("async_channel receiver error: {0}")]
  377. AsyncChannelRecvError(String),
  378. #[error("SetLogger (log crate) failed: {0}")]
  379. SetLoggerError(String),
  380. #[error("ValueIsNotObject")]
  381. ValueIsNotObject,
  382. #[error("No config file detected")]
  383. ConfigNotFound,
  384. #[error("Invalid config file detected")]
  385. ConfigInvalid,
  386. #[error("Failed decoding bincode: {0}")]
  387. ZkasDecoderError(String),
  388. #[cfg(feature = "util")]
  389. #[error("System clock is not correct!")]
  390. InvalidClock,
  391. #[error("Unsupported OS")]
  392. UnsupportedOS,
  393. #[error("System clock went backwards")]
  394. BackwardsTime(std::time::SystemTimeError),
  395. #[error("Detached task stopped")]
  396. DetachedTaskStopped,
  397. // ==============================================
  398. // Wrappers for other error types in this library
  399. // ==============================================
  400. #[error(transparent)]
  401. ClientFailed(#[from] ClientFailed),
  402. #[cfg(feature = "tx")]
  403. #[error(transparent)]
  404. TxVerifyFailed(#[from] TxVerifyFailed),
  405. //=============
  406. // clock
  407. //=============
  408. #[error("clock out of sync with peers: {0}")]
  409. ClockOutOfSync(String),
  410. // ================
  411. // DHT/Geode errors
  412. // ================
  413. #[error("Geode needs garbage collection")]
  414. GeodeNeedsGc,
  415. #[error("Geode file not found")]
  416. GeodeFileNotFound,
  417. #[error("Geode chunk not found")]
  418. GeodeChunkNotFound,
  419. #[error("Geode file route not found")]
  420. GeodeFileRouteNotFound,
  421. #[error("Geode chunk route not found")]
  422. GeodeChunkRouteNotFound,
  423. // ==================
  424. // Event Graph errors
  425. // ==================
  426. #[error("DAG sync failed")]
  427. DagSyncFailed,
  428. // =========
  429. // Catch-all
  430. // =========
  431. #[error("{0}")]
  432. Custom(String),
  433. }
  434. #[cfg(feature = "tx")]
  435. impl Error {
  436. /// Auxiliary function to retrieve the vector of erroneous
  437. /// transactions from a TxVerifyFailed error.
  438. /// In any other case, we return the error itself.
  439. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  440. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  441. return Ok(erroneous_txs.clone())
  442. };
  443. Err(self.clone())
  444. }
  445. }
  446. #[cfg(feature = "tx")]
  447. /// Transaction verification errors
  448. #[derive(Debug, Clone, thiserror::Error)]
  449. pub enum TxVerifyFailed {
  450. #[error("Transaction {0} already exists")]
  451. AlreadySeenTx(String),
  452. #[error("Invalid transaction signature")]
  453. InvalidSignature,
  454. #[error("Missing signatures in transaction")]
  455. MissingSignatures,
  456. #[error("Missing contract calls in transaction")]
  457. MissingCalls,
  458. #[error("Invalid ZK proof in transaction")]
  459. InvalidZkProof,
  460. #[error("Missing Money::Fee call in transaction")]
  461. MissingFee,
  462. #[error("Invalid Money::Fee call in transaction")]
  463. InvalidFee,
  464. #[error("Insufficient fee paid")]
  465. InsufficientFee,
  466. #[error("Erroneous transactions found")]
  467. ErroneousTxs(Vec<crate::tx::Transaction>),
  468. }
  469. /// Client module errors
  470. #[derive(Debug, Clone, thiserror::Error)]
  471. pub enum ClientFailed {
  472. #[error("IO error: {0}")]
  473. Io(std::io::ErrorKind),
  474. #[error("Not enough value: {0}")]
  475. NotEnoughValue(u64),
  476. #[error("Invalid address: {0}")]
  477. InvalidAddress(String),
  478. #[error("Invalid amount: {0}")]
  479. InvalidAmount(u64),
  480. #[error("Invalid token ID: {0}")]
  481. InvalidTokenId(String),
  482. #[error("Internal error: {0}")]
  483. InternalError(String),
  484. #[error("Verify error: {0}")]
  485. VerifyError(String),
  486. }
  487. #[cfg(feature = "rpc")]
  488. #[derive(Clone, Debug, thiserror::Error)]
  489. pub enum RpcError {
  490. #[error("Connection closed: {0}")]
  491. ConnectionClosed(String),
  492. #[error("Invalid JSON: {0}")]
  493. InvalidJson(String),
  494. #[error("IO Error: {0}")]
  495. IoError(std::io::ErrorKind),
  496. }
  497. #[cfg(feature = "rpc")]
  498. impl From<std::io::Error> for RpcError {
  499. fn from(err: std::io::Error) -> Self {
  500. Self::IoError(err.kind())
  501. }
  502. }
  503. #[cfg(feature = "rpc")]
  504. impl From<RpcError> for Error {
  505. fn from(err: RpcError) -> Self {
  506. Self::RpcServerError(err)
  507. }
  508. }
  509. impl From<Error> for ClientFailed {
  510. fn from(err: Error) -> Self {
  511. Self::InternalError(err.to_string())
  512. }
  513. }
  514. impl From<std::io::Error> for ClientFailed {
  515. fn from(err: std::io::Error) -> Self {
  516. Self::Io(err.kind())
  517. }
  518. }
  519. impl From<std::io::Error> for Error {
  520. fn from(err: std::io::Error) -> Self {
  521. Self::Io(err.kind())
  522. }
  523. }
  524. impl From<std::time::SystemTimeError> for Error {
  525. fn from(err: std::time::SystemTimeError) -> Self {
  526. Self::BackwardsTime(err)
  527. }
  528. }
  529. impl From<std::convert::Infallible> for Error {
  530. fn from(err: std::convert::Infallible) -> Self {
  531. Self::InfallibleError(err.to_string())
  532. }
  533. }
  534. impl From<()> for Error {
  535. fn from(_err: ()) -> Self {
  536. Self::InfallibleError("Infallible".into())
  537. }
  538. }
  539. #[cfg(feature = "smol")]
  540. impl<T> From<smol::channel::SendError<T>> for Error {
  541. fn from(err: smol::channel::SendError<T>) -> Self {
  542. Self::AsyncChannelSendError(err.to_string())
  543. }
  544. }
  545. #[cfg(feature = "smol")]
  546. impl From<smol::channel::RecvError> for Error {
  547. fn from(err: smol::channel::RecvError) -> Self {
  548. Self::AsyncChannelRecvError(err.to_string())
  549. }
  550. }
  551. impl From<log::SetLoggerError> for Error {
  552. fn from(err: log::SetLoggerError) -> Self {
  553. Self::SetLoggerError(err.to_string())
  554. }
  555. }
  556. #[cfg(feature = "rusqlite")]
  557. impl From<rusqlite::Error> for Error {
  558. fn from(err: rusqlite::Error) -> Self {
  559. Self::RusqliteError(err.to_string())
  560. }
  561. }
  562. #[cfg(feature = "halo2_proofs")]
  563. impl From<halo2_proofs::plonk::Error> for Error {
  564. fn from(err: halo2_proofs::plonk::Error) -> Self {
  565. Self::PlonkError(err.to_string())
  566. }
  567. }
  568. #[cfg(feature = "semver")]
  569. impl From<semver::Error> for Error {
  570. fn from(err: semver::Error) -> Self {
  571. Self::SemverError(err.to_string())
  572. }
  573. }
  574. /*
  575. #[cfg(feature = "tungstenite")]
  576. impl From<tungstenite::Error> for Error {
  577. fn from(err: tungstenite::Error) -> Self {
  578. Self::TungsteniteError(err.to_string())
  579. }
  580. }
  581. */
  582. #[cfg(feature = "async-tungstenite")]
  583. impl From<async_tungstenite::tungstenite::Error> for Error {
  584. fn from(err: async_tungstenite::tungstenite::Error) -> Self {
  585. Self::TungsteniteError(err.to_string())
  586. }
  587. }
  588. #[cfg(feature = "async-rustls")]
  589. impl From<async_rustls::rustls::client::InvalidDnsNameError> for Error {
  590. fn from(err: async_rustls::rustls::client::InvalidDnsNameError) -> Self {
  591. Self::RustlsInvalidDns(err.to_string())
  592. }
  593. }
  594. #[cfg(feature = "serde_json")]
  595. impl From<serde_json::Error> for Error {
  596. fn from(err: serde_json::Error) -> Self {
  597. Self::SerdeJsonError(err.to_string())
  598. }
  599. }
  600. #[cfg(feature = "tinyjson")]
  601. impl From<tinyjson::JsonParseError> for Error {
  602. fn from(err: tinyjson::JsonParseError) -> Self {
  603. Self::JsonParseError(err.to_string())
  604. }
  605. }
  606. #[cfg(feature = "tinyjson")]
  607. impl From<tinyjson::JsonGenerateError> for Error {
  608. fn from(err: tinyjson::JsonGenerateError) -> Self {
  609. Self::JsonGenerateError(err.to_string())
  610. }
  611. }
  612. #[cfg(feature = "fast-socks5")]
  613. impl From<fast_socks5::SocksError> for Error {
  614. fn from(err: fast_socks5::SocksError) -> Self {
  615. Self::SocksError(err.to_string())
  616. }
  617. }
  618. #[cfg(feature = "wasm-runtime")]
  619. impl From<wasmer::CompileError> for Error {
  620. fn from(err: wasmer::CompileError) -> Self {
  621. Self::WasmerCompileError(err.to_string())
  622. }
  623. }
  624. #[cfg(feature = "wasm-runtime")]
  625. impl From<wasmer::ExportError> for Error {
  626. fn from(err: wasmer::ExportError) -> Self {
  627. Self::WasmerExportError(err.to_string())
  628. }
  629. }
  630. #[cfg(feature = "wasm-runtime")]
  631. impl From<wasmer::RuntimeError> for Error {
  632. fn from(err: wasmer::RuntimeError) -> Self {
  633. Self::WasmerRuntimeError(err.to_string())
  634. }
  635. }
  636. #[cfg(feature = "wasm-runtime")]
  637. impl From<wasmer::InstantiationError> for Error {
  638. fn from(err: wasmer::InstantiationError) -> Self {
  639. Self::WasmerInstantiationError(err.to_string())
  640. }
  641. }
  642. #[cfg(feature = "wasm-runtime")]
  643. impl From<wasmer::MemoryAccessError> for Error {
  644. fn from(err: wasmer::MemoryAccessError) -> Self {
  645. Self::WasmerMemoryError(err.to_string())
  646. }
  647. }
  648. #[cfg(feature = "wasm-runtime")]
  649. impl From<wasmer::MemoryError> for Error {
  650. fn from(err: wasmer::MemoryError) -> Self {
  651. Self::WasmerOomError(err.to_string())
  652. }
  653. }
  654. #[cfg(feature = "darkfi-sdk")]
  655. impl From<darkfi_sdk::error::ContractError> for Error {
  656. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  657. Self::ContractError(err)
  658. }
  659. }
  660. #[cfg(feature = "darkfi-sdk")]
  661. impl From<darkfi_sdk::error::DarkTreeError> for Error {
  662. fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
  663. Self::DarkTreeError(err)
  664. }
  665. }