error.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //! LND Errors
  2. use thiserror::Error;
  3. use tonic::Status;
  4. /// LND Error
  5. #[derive(Debug, Error)]
  6. pub enum Error {
  7. /// Invoice amount not defined
  8. #[error("Unknown invoice amount")]
  9. UnknownInvoiceAmount,
  10. /// Unknown invoice
  11. #[error("Unknown invoice")]
  12. UnknownInvoice,
  13. /// Connection error
  14. #[error("LND connection error")]
  15. Connection,
  16. /// Invalid hash
  17. #[error("Invalid hash")]
  18. InvalidHash,
  19. /// Payment failed
  20. #[error("LND payment failed")]
  21. PaymentFailed,
  22. /// Unknown payment status
  23. #[error("LND unknown payment status")]
  24. UnknownPaymentStatus,
  25. /// Missing last hop in route
  26. #[error("LND missing last hop in route")]
  27. MissingLastHop,
  28. /// Amount overflow
  29. #[error("Amount overflow")]
  30. AmountOverflow,
  31. /// Errors coming from the backend
  32. #[error("LND error: `{0}`")]
  33. LndError(Status),
  34. /// Errors invalid config
  35. #[error("LND invalid config: `{0}`")]
  36. InvalidConfig(String),
  37. /// Could not read file
  38. #[error("Could not read file")]
  39. ReadFile,
  40. }
  41. impl From<Error> for cdk_common::payment::Error {
  42. fn from(e: Error) -> Self {
  43. Self::Lightning(Box::new(e))
  44. }
  45. }
  46. impl From<tonic::transport::Error> for Error {
  47. fn from(e: tonic::transport::Error) -> Self {
  48. Error::InvalidConfig(format!("Transport error: {e}"))
  49. }
  50. }