error.rs 21 KB

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