error.rs 20 KB

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