error.rs 21 KB

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