error.rs 22 KB

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