error.rs 22 KB

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