error.rs 21 KB

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