error.rs 21 KB

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