error.rs 22 KB

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