error.rs 21 KB

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