error.rs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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 = "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("Proposal already exists")]
  247. ProposalAlreadyExists,
  248. #[error("Miner task stopped")]
  249. MinerTaskStopped,
  250. #[error("Calculated total work is zero")]
  251. PoWTotalWorkIsZero,
  252. #[error("Erroneous cutoff calculation")]
  253. PoWCuttofCalculationError,
  254. #[error("Provided timestamp is invalid")]
  255. PoWInvalidTimestamp,
  256. #[error("Provided output hash is greater than current target")]
  257. PoWInvalidOutHash,
  258. // ===============
  259. // Database errors
  260. // ===============
  261. #[cfg(feature = "rusqlite")]
  262. #[error("rusqlite error: {0}")]
  263. RusqliteError(String),
  264. #[cfg(feature = "sled")]
  265. #[error(transparent)]
  266. SledError(#[from] sled::Error),
  267. #[cfg(feature = "sled")]
  268. #[error(transparent)]
  269. SledTransactionError(#[from] sled::transaction::TransactionError),
  270. #[error("Transaction {0} not found in database")]
  271. TransactionNotFound(String),
  272. #[error("Transaction already seen")]
  273. TransactionAlreadySeen,
  274. #[error("Input vectors have different length")]
  275. InvalidInputLengths,
  276. #[error("Header {0} not found in database")]
  277. HeaderNotFound(String),
  278. #[error("Block {0} is invalid")]
  279. BlockIsInvalid(String),
  280. #[error("Block version {0} is invalid")]
  281. BlockVersionIsInvalid(u8),
  282. #[error("Block {0} already in database")]
  283. BlockAlreadyExists(String),
  284. #[error("Block {0} not found in database")]
  285. BlockNotFound(String),
  286. #[error("Block with order number {0} not found in database")]
  287. BlockNumberNotFound(u64),
  288. #[error("Block difficulty for height number {0} not found in database")]
  289. BlockDifficultyNotFound(u64),
  290. #[error("Block {0} contains 0 transactions")]
  291. BlockContainsNoTransactions(String),
  292. #[error("Verifying slot missmatch")]
  293. VerifyingSlotMissmatch(),
  294. #[error("Slot {0} is invalid")]
  295. SlotIsInvalid(u64),
  296. #[error("Slot {0} not found in database")]
  297. SlotNotFound(u64),
  298. #[error("Block {0} slots not found in database")]
  299. BlockSlotsNotFound(String),
  300. #[error("Future slot {0} was received")]
  301. FutureSlotReceived(u64),
  302. #[error("Contract {0} not found in database")]
  303. ContractNotFound(String),
  304. #[error("Contract state tree not found")]
  305. ContractStateNotFound,
  306. #[error("Contract already initialized")]
  307. ContractAlreadyInitialized,
  308. #[error("zkas bincode not found in sled database")]
  309. ZkasBincodeNotFound,
  310. // ===================
  311. // wasm runtime errors
  312. // ===================
  313. #[cfg(feature = "wasm-runtime")]
  314. #[error("Wasmer compile error: {0}")]
  315. WasmerCompileError(String),
  316. #[cfg(feature = "wasm-runtime")]
  317. #[error("Wasmer export error: {0}")]
  318. WasmerExportError(String),
  319. #[cfg(feature = "wasm-runtime")]
  320. #[error("Wasmer runtime error: {0}")]
  321. WasmerRuntimeError(String),
  322. #[cfg(feature = "wasm-runtime")]
  323. #[error("Wasmer instantiation error: {0}")]
  324. WasmerInstantiationError(String),
  325. #[cfg(feature = "wasm-runtime")]
  326. #[error("wasm memory error")]
  327. WasmerMemoryError(String),
  328. #[cfg(feature = "wasm-runtime")]
  329. #[error("wasm runtime out of memory")]
  330. WasmerOomError(String),
  331. #[cfg(feature = "darkfi-sdk")]
  332. #[error("Contract execution failed: {0}")]
  333. ContractError(darkfi_sdk::error::ContractError),
  334. #[cfg(feature = "darkfi-sdk")]
  335. #[error("Invalid DarkTree: {0}")]
  336. DarkTreeError(darkfi_sdk::error::DarkTreeError),
  337. #[cfg(feature = "blockchain")]
  338. #[error("contract wasm bincode not found")]
  339. WasmBincodeNotFound,
  340. #[cfg(feature = "wasm-runtime")]
  341. #[error("contract initialize error")]
  342. ContractInitError(u64),
  343. #[cfg(feature = "wasm-runtime")]
  344. #[error("contract execution error")]
  345. ContractExecError(u64),
  346. #[cfg(feature = "wasm-runtime")]
  347. #[error("wasm function ACL denied")]
  348. WasmFunctionAclDenied,
  349. // ====================
  350. // Event Graph errors
  351. // ====================
  352. #[error("Event is not found in tree: {0}")]
  353. EventNotFound(String),
  354. #[error("Event is invalid")]
  355. EventIsInvalid,
  356. // ====================
  357. // Miscellaneous errors
  358. // ====================
  359. #[error("IO error: {0}")]
  360. Io(std::io::ErrorKind),
  361. #[error("Infallible error: {0}")]
  362. InfallibleError(String),
  363. #[cfg(feature = "smol")]
  364. #[error("async_channel sender error: {0}")]
  365. AsyncChannelSendError(String),
  366. #[cfg(feature = "smol")]
  367. #[error("async_channel receiver error: {0}")]
  368. AsyncChannelRecvError(String),
  369. #[error("SetLogger (log crate) failed: {0}")]
  370. SetLoggerError(String),
  371. #[error("ValueIsNotObject")]
  372. ValueIsNotObject,
  373. #[error("No config file detected")]
  374. ConfigNotFound,
  375. #[error("Invalid config file detected")]
  376. ConfigInvalid,
  377. #[error("Failed decoding bincode: {0}")]
  378. ZkasDecoderError(String),
  379. #[cfg(feature = "util")]
  380. #[error("System clock is not correct!")]
  381. InvalidClock,
  382. #[error("Unsupported OS")]
  383. UnsupportedOS,
  384. #[error("System clock went backwards")]
  385. BackwardsTime(std::time::SystemTimeError),
  386. #[error("Detached task stopped")]
  387. DetachedTaskStopped,
  388. // ==============================================
  389. // Wrappers for other error types in this library
  390. // ==============================================
  391. #[error(transparent)]
  392. ClientFailed(#[from] ClientFailed),
  393. #[cfg(feature = "tx")]
  394. #[error(transparent)]
  395. TxVerifyFailed(#[from] TxVerifyFailed),
  396. //=============
  397. // clock
  398. //=============
  399. #[error("clock out of sync with peers: {0}")]
  400. ClockOutOfSync(String),
  401. // ================
  402. // DHT/Geode errors
  403. // ================
  404. #[error("Geode needs garbage collection")]
  405. GeodeNeedsGc,
  406. #[error("Geode file not found")]
  407. GeodeFileNotFound,
  408. #[error("Geode chunk not found")]
  409. GeodeChunkNotFound,
  410. #[error("Geode file route not found")]
  411. GeodeFileRouteNotFound,
  412. #[error("Geode chunk route not found")]
  413. GeodeChunkRouteNotFound,
  414. // ==================
  415. // Event Graph errors
  416. // ==================
  417. #[error("DAG sync failed")]
  418. DagSyncFailed,
  419. // =========
  420. // Catch-all
  421. // =========
  422. #[error("{0}")]
  423. Custom(String),
  424. }
  425. #[cfg(feature = "tx")]
  426. impl Error {
  427. /// Auxiliary function to retrieve the vector of erroneous
  428. /// transactions from a TxVerifyFailed error.
  429. /// In any other case, we return the error itself.
  430. pub fn retrieve_erroneous_txs(&self) -> Result<Vec<crate::tx::Transaction>> {
  431. if let Self::TxVerifyFailed(TxVerifyFailed::ErroneousTxs(erroneous_txs)) = self {
  432. return Ok(erroneous_txs.clone())
  433. };
  434. Err(self.clone())
  435. }
  436. }
  437. #[cfg(feature = "tx")]
  438. /// Transaction verification errors
  439. #[derive(Debug, Clone, thiserror::Error)]
  440. pub enum TxVerifyFailed {
  441. #[error("Transaction {0} already exists")]
  442. AlreadySeenTx(String),
  443. #[error("Invalid transaction signature")]
  444. InvalidSignature,
  445. #[error("Missing signatures in transaction")]
  446. MissingSignatures,
  447. #[error("Missing contract calls in transaction")]
  448. MissingCalls,
  449. #[error("Invalid ZK proof in transaction")]
  450. InvalidZkProof,
  451. #[error("Missing Money::Fee call in transaction")]
  452. MissingFee,
  453. #[error("Invalid Money::Fee call in transaction")]
  454. InvalidFee,
  455. #[error("Insufficient fee paid")]
  456. InsufficientFee,
  457. #[error("Erroneous transactions found")]
  458. ErroneousTxs(Vec<crate::tx::Transaction>),
  459. }
  460. /// Client module errors
  461. #[derive(Debug, Clone, thiserror::Error)]
  462. pub enum ClientFailed {
  463. #[error("IO error: {0}")]
  464. Io(std::io::ErrorKind),
  465. #[error("Not enough value: {0}")]
  466. NotEnoughValue(u64),
  467. #[error("Invalid address: {0}")]
  468. InvalidAddress(String),
  469. #[error("Invalid amount: {0}")]
  470. InvalidAmount(u64),
  471. #[error("Invalid token ID: {0}")]
  472. InvalidTokenId(String),
  473. #[error("Internal error: {0}")]
  474. InternalError(String),
  475. #[error("Verify error: {0}")]
  476. VerifyError(String),
  477. }
  478. #[cfg(feature = "rpc")]
  479. #[derive(Clone, Debug, thiserror::Error)]
  480. pub enum RpcError {
  481. #[error("Connection closed: {0}")]
  482. ConnectionClosed(String),
  483. #[error("Invalid JSON: {0}")]
  484. InvalidJson(String),
  485. #[error("IO Error: {0}")]
  486. IoError(std::io::ErrorKind),
  487. }
  488. #[cfg(feature = "rpc")]
  489. impl From<std::io::Error> for RpcError {
  490. fn from(err: std::io::Error) -> Self {
  491. Self::IoError(err.kind())
  492. }
  493. }
  494. #[cfg(feature = "rpc")]
  495. impl From<RpcError> for Error {
  496. fn from(err: RpcError) -> Self {
  497. Self::RpcServerError(err)
  498. }
  499. }
  500. impl From<Error> for ClientFailed {
  501. fn from(err: Error) -> Self {
  502. Self::InternalError(err.to_string())
  503. }
  504. }
  505. impl From<std::io::Error> for ClientFailed {
  506. fn from(err: std::io::Error) -> Self {
  507. Self::Io(err.kind())
  508. }
  509. }
  510. impl From<std::io::Error> for Error {
  511. fn from(err: std::io::Error) -> Self {
  512. Self::Io(err.kind())
  513. }
  514. }
  515. impl From<std::time::SystemTimeError> for Error {
  516. fn from(err: std::time::SystemTimeError) -> Self {
  517. Self::BackwardsTime(err)
  518. }
  519. }
  520. impl From<std::convert::Infallible> for Error {
  521. fn from(err: std::convert::Infallible) -> Self {
  522. Self::InfallibleError(err.to_string())
  523. }
  524. }
  525. impl From<()> for Error {
  526. fn from(_err: ()) -> Self {
  527. Self::InfallibleError("Infallible".into())
  528. }
  529. }
  530. #[cfg(feature = "smol")]
  531. impl<T> From<smol::channel::SendError<T>> for Error {
  532. fn from(err: smol::channel::SendError<T>) -> Self {
  533. Self::AsyncChannelSendError(err.to_string())
  534. }
  535. }
  536. #[cfg(feature = "smol")]
  537. impl From<smol::channel::RecvError> for Error {
  538. fn from(err: smol::channel::RecvError) -> Self {
  539. Self::AsyncChannelRecvError(err.to_string())
  540. }
  541. }
  542. impl From<log::SetLoggerError> for Error {
  543. fn from(err: log::SetLoggerError) -> Self {
  544. Self::SetLoggerError(err.to_string())
  545. }
  546. }
  547. #[cfg(feature = "rusqlite")]
  548. impl From<rusqlite::Error> for Error {
  549. fn from(err: rusqlite::Error) -> Self {
  550. Self::RusqliteError(err.to_string())
  551. }
  552. }
  553. #[cfg(feature = "halo2_proofs")]
  554. impl From<halo2_proofs::plonk::Error> for Error {
  555. fn from(err: halo2_proofs::plonk::Error) -> Self {
  556. Self::PlonkError(err.to_string())
  557. }
  558. }
  559. #[cfg(feature = "semver")]
  560. impl From<semver::Error> for Error {
  561. fn from(err: semver::Error) -> Self {
  562. Self::SemverError(err.to_string())
  563. }
  564. }
  565. /*
  566. #[cfg(feature = "tungstenite")]
  567. impl From<tungstenite::Error> for Error {
  568. fn from(err: tungstenite::Error) -> Self {
  569. Self::TungsteniteError(err.to_string())
  570. }
  571. }
  572. */
  573. #[cfg(feature = "async-tungstenite")]
  574. impl From<async_tungstenite::tungstenite::Error> for Error {
  575. fn from(err: async_tungstenite::tungstenite::Error) -> Self {
  576. Self::TungsteniteError(err.to_string())
  577. }
  578. }
  579. #[cfg(feature = "async-rustls")]
  580. impl From<async_rustls::rustls::client::InvalidDnsNameError> for Error {
  581. fn from(err: async_rustls::rustls::client::InvalidDnsNameError) -> Self {
  582. Self::RustlsInvalidDns(err.to_string())
  583. }
  584. }
  585. #[cfg(feature = "serde_json")]
  586. impl From<serde_json::Error> for Error {
  587. fn from(err: serde_json::Error) -> Self {
  588. Self::SerdeJsonError(err.to_string())
  589. }
  590. }
  591. #[cfg(feature = "tinyjson")]
  592. impl From<tinyjson::JsonParseError> for Error {
  593. fn from(err: tinyjson::JsonParseError) -> Self {
  594. Self::JsonParseError(err.to_string())
  595. }
  596. }
  597. #[cfg(feature = "tinyjson")]
  598. impl From<tinyjson::JsonGenerateError> for Error {
  599. fn from(err: tinyjson::JsonGenerateError) -> Self {
  600. Self::JsonGenerateError(err.to_string())
  601. }
  602. }
  603. #[cfg(feature = "fast-socks5")]
  604. impl From<fast_socks5::SocksError> for Error {
  605. fn from(err: fast_socks5::SocksError) -> Self {
  606. Self::SocksError(err.to_string())
  607. }
  608. }
  609. #[cfg(feature = "wasm-runtime")]
  610. impl From<wasmer::CompileError> for Error {
  611. fn from(err: wasmer::CompileError) -> Self {
  612. Self::WasmerCompileError(err.to_string())
  613. }
  614. }
  615. #[cfg(feature = "wasm-runtime")]
  616. impl From<wasmer::ExportError> for Error {
  617. fn from(err: wasmer::ExportError) -> Self {
  618. Self::WasmerExportError(err.to_string())
  619. }
  620. }
  621. #[cfg(feature = "wasm-runtime")]
  622. impl From<wasmer::RuntimeError> for Error {
  623. fn from(err: wasmer::RuntimeError) -> Self {
  624. Self::WasmerRuntimeError(err.to_string())
  625. }
  626. }
  627. #[cfg(feature = "wasm-runtime")]
  628. impl From<wasmer::InstantiationError> for Error {
  629. fn from(err: wasmer::InstantiationError) -> Self {
  630. Self::WasmerInstantiationError(err.to_string())
  631. }
  632. }
  633. #[cfg(feature = "wasm-runtime")]
  634. impl From<wasmer::MemoryAccessError> for Error {
  635. fn from(err: wasmer::MemoryAccessError) -> Self {
  636. Self::WasmerMemoryError(err.to_string())
  637. }
  638. }
  639. #[cfg(feature = "wasm-runtime")]
  640. impl From<wasmer::MemoryError> for Error {
  641. fn from(err: wasmer::MemoryError) -> Self {
  642. Self::WasmerOomError(err.to_string())
  643. }
  644. }
  645. #[cfg(feature = "darkfi-sdk")]
  646. impl From<darkfi_sdk::error::ContractError> for Error {
  647. fn from(err: darkfi_sdk::error::ContractError) -> Self {
  648. Self::ContractError(err)
  649. }
  650. }
  651. #[cfg(feature = "darkfi-sdk")]
  652. impl From<darkfi_sdk::error::DarkTreeError> for Error {
  653. fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
  654. Self::DarkTreeError(err)
  655. }
  656. }