error.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. pub type Result<T> = std::result::Result<T, Error>;
  2. #[derive(Debug, Clone, thiserror::Error)]
  3. pub enum Error {
  4. /// Service
  5. #[error("Services Error: `{0}`")]
  6. ServicesError(&'static str),
  7. #[error("Client failed: `{0}`")]
  8. ClientFailed(String),
  9. #[cfg(feature = "btc")]
  10. #[error(transparent)]
  11. BtcFailed(#[from] crate::service::BtcFailed),
  12. #[cfg(feature = "sol")]
  13. #[error("Sol client failed: `{0}`")]
  14. SolFailed(String),
  15. #[cfg(feature = "eth")]
  16. #[error(transparent)]
  17. EthFailed(#[from] crate::service::EthFailed),
  18. #[error("BridgeError Error: `{0}`")]
  19. BridgeError(String),
  20. #[error("Async_channel sender error")]
  21. AsyncChannelSenderError,
  22. #[error(transparent)]
  23. AsyncChannelReceiverError(#[from] async_channel::RecvError),
  24. }
  25. #[cfg(feature = "sol")]
  26. impl From<crate::service::SolFailed> for Error {
  27. fn from(err: crate::service::SolFailed) -> Error {
  28. Error::SolFailed(err.to_string())
  29. }
  30. }
  31. impl From<darkfi::Error> for Error {
  32. fn from(err: darkfi::Error) -> Error {
  33. Error::ClientFailed(err.to_string())
  34. }
  35. }
  36. impl<T> From<async_channel::SendError<T>> for Error {
  37. fn from(_err: async_channel::SendError<T>) -> Error {
  38. Error::AsyncChannelSenderError
  39. }
  40. }