error.rs 21 KB

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