error.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2023 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. pub type Result<T> = std::result::Result<T, Error>;
  19. #[derive(Debug, Clone, thiserror::Error)]
  20. pub enum Error {
  21. /// Service
  22. #[error("Services Error: `{0}`")]
  23. ServicesError(&'static str),
  24. #[error("Client failed: `{0}`")]
  25. ClientFailed(String),
  26. #[cfg(feature = "btc")]
  27. #[error(transparent)]
  28. BtcFailed(#[from] crate::service::BtcFailed),
  29. #[cfg(feature = "sol")]
  30. #[error("Sol client failed: `{0}`")]
  31. SolFailed(String),
  32. #[cfg(feature = "eth")]
  33. #[error(transparent)]
  34. EthFailed(#[from] crate::service::EthFailed),
  35. #[error("BridgeError Error: `{0}`")]
  36. BridgeError(String),
  37. #[error("Async_channel sender error")]
  38. AsyncChannelSenderError,
  39. #[error(transparent)]
  40. AsyncChannelReceiverError(#[from] async_channel::RecvError),
  41. }
  42. #[cfg(feature = "sol")]
  43. impl From<crate::service::SolFailed> for Error {
  44. fn from(err: crate::service::SolFailed) -> Error {
  45. Error::SolFailed(err.to_string())
  46. }
  47. }
  48. impl From<darkfi::Error> for Error {
  49. fn from(err: darkfi::Error) -> Error {
  50. Error::ClientFailed(err.to_string())
  51. }
  52. }
  53. impl<T> From<async_channel::SendError<T>> for Error {
  54. fn from(_err: async_channel::SendError<T>) -> Error {
  55. Error::AsyncChannelSenderError
  56. }
  57. }