error.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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")]
  338. ContractError(darkfi_sdk::error::ContractError),
  339. #[cfg(feature = "blockchain")]
  340. #[error("contract wasm bincode not found")]
  341. WasmBincodeNotFound,
  342. #[cfg(feature = "wasm-runtime")]
  343. #[error("contract initialize error")]
  344. ContractInitError(u64),
  345. #[cfg(feature = "wasm-runtime")]
  346. #[error("contract execution error")]
  347. ContractExecError(u64),
  348. // ====================
  349. // Event Graph errors
  350. // ====================
  351. #[error("Event is not found in tree: {0}")]
  352. EventNotFound(String),
  353. // ====================
  354. // Miscellaneous errors
  355. // ====================
  356. #[error("IO error: {0}")]
  357. Io(std::io::ErrorKind),
  358. #[error("Infallible error: {0}")]
  359. InfallibleError(String),
  360. #[cfg(feature = "smol")]
  361. #[error("async_channel sender error: {0}")]
  362. AsyncChannelSendError(String),
  363. #[cfg(feature = "smol")]
  364. #[error("async_channel receiver error: {0}")]
  365. AsyncChannelRecvError(String),
  366. #[error("SetLogger (log crate) failed: {0}")]
  367. SetLoggerError(String),
  368. #[error("ValueIsNotObject")]
  369. ValueIsNotObject,
  370. #[error("No config file detected")]
  371. ConfigNotFound,
  372. #[error("Invalid config file detected")]
  373. ConfigInvalid,
  374. #[error("Failed decoding bincode: {0}")]
  375. ZkasDecoderError(String),
  376. #[cfg(feature = "util")]
  377. #[error("System clock is not correct!")]
  378. InvalidClock,
  379. #[error("Unsupported OS")]
  380. UnsupportedOS,
  381. #[error("System clock went backwards")]
  382. BackwardsTime(std::time::SystemTimeError),
  383. #[error("Detached task stopped")]
  384. DetachedTaskStopped,
  385. // ==============================================
  386. // Wrappers for other error types in this library
  387. // ==============================================
  388. #[error(transparent)]
  389. ClientFailed(#[from] ClientFailed),
  390. #[cfg(feature = "tx")]
  391. #[error(transparent)]
  392. TxVerifyFailed(#[from] TxVerifyFailed),
  393. //=============
  394. // clock
  395. //=============
  396. #[error("clock out of sync with peers: {0}")]
  397. ClockOutOfSync(String),
  398. // ================
  399. // DHT/Geode errors
  400. // ================
  401. #[error("Geode needs garbage collection")]
  402. GeodeNeedsGc,
  403. #[error("Geode file not found")]
  404. GeodeFileNotFound,
  405. #[error("Geode chunk not found")]
  406. GeodeChunkNotFound,
  407. #[error("Geode file route not found")]
  408. GeodeFileRouteNotFound,
  409. #[error("Geode chunk route not found")]
  410. GeodeChunkRouteNotFound,
  411. // ==================
  412. // Event Graph errors
  413. // ==================
  414. #[error("DAG sync failed")]
  415. DagSyncFailed,
  416. // =========
  417. // Catch-all
  418. // =========
  419. #[error("{0}")]
  420. Custom(String),
  421. }
  422. #[cfg(feature = "tx")]
  423. impl Error {
  424. /// Auxiliary function to retrieve the vector of erroneous
  425. /// transactions from a TxVerifyFailed error.
  426. /// In any other case, we return the error itself.
  427. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  428. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  429. return Ok(erroneous_txs.clone())
  430. };
  431. Err(self.clone())
  432. }
  433. }
  434. #[cfg(feature = "tx")]
  435. /// Transaction verification errors
  436. #[derive(Debug, Clone, thiserror::Error)]
  437. pub enum TxVerifyFailed {
  438. #[error("Transaction {0} already exists")]
  439. AlreadySeenTx(String),
  440. #[error("Invalid transaction signature")]
  441. InvalidSignature,
  442. #[error("Missing signatures in transaction")]
  443. MissingSignatures,
  444. #[error("Missing contract calls in transaction")]
  445. MissingCalls,
  446. #[error("Missing Money::Fee call in transaction")]
  447. MissingFee,
  448. #[error("Invalid ZK proof in transaction")]
  449. InvalidZkProof,
  450. #[error("Erroneous transactions found")]
  451. ErroneousTxs(Vec<crate::tx::Transaction>),
  452. }
  453. /// Client module errors
  454. #[derive(Debug, Clone, thiserror::Error)]
  455. pub enum ClientFailed {
  456. #[error("IO error: {0}")]
  457. Io(std::io::ErrorKind),
  458. #[error("Not enough value: {0}")]
  459. NotEnoughValue(u64),
  460. #[error("Invalid address: {0}")]
  461. InvalidAddress(String),
  462. #[error("Invalid amount: {0}")]
  463. InvalidAmount(u64),
  464. #[error("Invalid token ID: {0}")]
  465. InvalidTokenId(String),
  466. #[error("Internal error: {0}")]
  467. InternalError(String),
  468. #[error("Verify error: {0}")]
  469. VerifyError(String),
  470. }
  471. #[cfg(feature = "rpc")]
  472. #[derive(Clone, Debug, thiserror::Error)]
  473. pub enum RpcError {
  474. #[error("Connection closed: {0}")]
  475. ConnectionClosed(String),
  476. #[error("Invalid JSON: {0}")]
  477. InvalidJson(String),
  478. #[error("IO Error: {0}")]
  479. IoError(std::io::ErrorKind),
  480. }
  481. #[cfg(feature = "rpc")]
  482. impl From<std::io::Error> for RpcError {
  483. fn from(err: std::io::Error) -> Self {
  484. Self::IoError(err.kind())
  485. }
  486. }
  487. #[cfg(feature = "rpc")]
  488. impl From<RpcError> for Error {
  489. fn from(err: RpcError) -> Self {
  490. Self::RpcServerError(err)
  491. }
  492. }
  493. impl From<Error> for ClientFailed {
  494. fn from(err: Error) -> Self {
  495. Self::InternalError(err.to_string())
  496. }
  497. }
  498. impl From<std::io::Error> for ClientFailed {
  499. fn from(err: std::io::Error) -> Self {
  500. Self::Io(err.kind())
  501. }
  502. }
  503. impl From<std::io::Error> for Error {
  504. fn from(err: std::io::Error) -> Self {
  505. Self::Io(err.kind())
  506. }
  507. }
  508. impl From<std::time::SystemTimeError> for Error {
  509. fn from(err: std::time::SystemTimeError) -> Self {
  510. Self::BackwardsTime(err)
  511. }
  512. }
  513. impl From<std::convert::Infallible> for Error {
  514. fn from(err: std::convert::Infallible) -> Self {
  515. Self::InfallibleError(err.to_string())
  516. }
  517. }
  518. impl From<()> for Error {
  519. fn from(_err: ()) -> Self {
  520. Self::InfallibleError("Infallible".into())
  521. }
  522. }
  523. #[cfg(feature = "smol")]
  524. impl<T> From<smol::channel::SendError<T>> for Error {
  525. fn from(err: smol::channel::SendError<T>) -> Self {
  526. Self::AsyncChannelSendError(err.to_string())
  527. }
  528. }
  529. #[cfg(feature = "smol")]
  530. impl From<smol::channel::RecvError> for Error {
  531. fn from(err: smol::channel::RecvError) -> Self {
  532. Self::AsyncChannelRecvError(err.to_string())
  533. }
  534. }
  535. impl From<log::SetLoggerError> for Error {
  536. fn from(err: log::SetLoggerError) -> Self {
  537. Self::SetLoggerError(err.to_string())
  538. }
  539. }
  540. #[cfg(feature = "rusqlite")]
  541. impl From<rusqlite::Error> for Error {
  542. fn from(err: rusqlite::Error) -> Self {
  543. Self::RusqliteError(err.to_string())
  544. }
  545. }
  546. #[cfg(feature = "halo2_proofs")]
  547. impl From<halo2_proofs::plonk::Error> for Error {
  548. fn from(err: halo2_proofs::plonk::Error) -> Self {
  549. Self::PlonkError(err.to_string())
  550. }
  551. }
  552. #[cfg(feature = "semver")]
  553. impl From<semver::Error> for Error {
  554. fn from(err: semver::Error) -> Self {
  555. Self::SemverError(err.to_string())
  556. }
  557. }
  558. /*
  559. #[cfg(feature = "tungstenite")]
  560. impl From<tungstenite::Error> for Error {
  561. fn from(err: tungstenite::Error) -> Self {
  562. Self::TungsteniteError(err.to_string())
  563. }
  564. }
  565. */
  566. #[cfg(feature = "async-tungstenite")]
  567. impl From<async_tungstenite::tungstenite::Error> for Error {
  568. fn from(err: async_tungstenite::tungstenite::Error) -> Self {
  569. Self::TungsteniteError(err.to_string())
  570. }
  571. }
  572. #[cfg(feature = "async-rustls")]
  573. impl From<async_rustls::rustls::client::InvalidDnsNameError> for Error {
  574. fn from(err: async_rustls::rustls::client::InvalidDnsNameError) -> Self {
  575. Self::RustlsInvalidDns(err.to_string())
  576. }
  577. }
  578. #[cfg(feature = "serde_json")]
  579. impl From<serde_json::Error> for Error {
  580. fn from(err: serde_json::Error) -> Self {
  581. Self::SerdeJsonError(err.to_string())
  582. }
  583. }
  584. #[cfg(feature = "tinyjson")]
  585. impl From<tinyjson::JsonParseError> for Error {
  586. fn from(err: tinyjson::JsonParseError) -> Self {
  587. Self::JsonParseError(err.to_string())
  588. }
  589. }
  590. #[cfg(feature = "tinyjson")]
  591. impl From<tinyjson::JsonGenerateError> for Error {
  592. fn from(err: tinyjson::JsonGenerateError) -> Self {
  593. Self::JsonGenerateError(err.to_string())
  594. }
  595. }
  596. #[cfg(feature = "fast-socks5")]
  597. impl From<fast_socks5::SocksError> for Error {
  598. fn from(err: fast_socks5::SocksError) -> Self {
  599. Self::SocksError(err.to_string())
  600. }
  601. }
  602. #[cfg(feature = "wasm-runtime")]
  603. impl From<wasmer::CompileError> for Error {
  604. fn from(err: wasmer::CompileError) -> Self {
  605. Self::WasmerCompileError(err.to_string())
  606. }
  607. }
  608. #[cfg(feature = "wasm-runtime")]
  609. impl From<wasmer::ExportError> for Error {
  610. fn from(err: wasmer::ExportError) -> Self {
  611. Self::WasmerExportError(err.to_string())
  612. }
  613. }
  614. #[cfg(feature = "wasm-runtime")]
  615. impl From<wasmer::RuntimeError> for Error {
  616. fn from(err: wasmer::RuntimeError) -> Self {
  617. Self::WasmerRuntimeError(err.to_string())
  618. }
  619. }
  620. #[cfg(feature = "wasm-runtime")]
  621. impl From<wasmer::InstantiationError> for Error {
  622. fn from(err: wasmer::InstantiationError) -> Self {
  623. Self::WasmerInstantiationError(err.to_string())
  624. }
  625. }
  626. #[cfg(feature = "wasm-runtime")]
  627. impl From<wasmer::MemoryAccessError> for Error {
  628. fn from(err: wasmer::MemoryAccessError) -> Self {
  629. Self::WasmerMemoryError(err.to_string())
  630. }
  631. }
  632. #[cfg(feature = "wasm-runtime")]
  633. impl From<wasmer::MemoryError> for Error {
  634. fn from(err: wasmer::MemoryError) -> Self {
  635. Self::WasmerOomError(err.to_string())
  636. }
  637. }
  638. #[cfg(feature = "darkfi-sdk")]
  639. impl From<darkfi_sdk::error::ContractError> for Error {
  640. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  641. Self::ContractError(err)
  642. }
  643. }