error.rs 20 KB

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