error.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use std::fmt;
  2. use cashu::lightning_invoice::ParseOrSemanticError;
  3. pub type Result<T, E = CashuError> = std::result::Result<T, E>;
  4. #[derive(Debug)]
  5. pub enum CashuError {
  6. Generic { err: String },
  7. }
  8. impl fmt::Display for CashuError {
  9. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  10. match self {
  11. Self::Generic { err } => write!(f, "{err}"),
  12. }
  13. }
  14. }
  15. impl From<cashu::error::Error> for CashuError {
  16. fn from(err: cashu::error::Error) -> Self {
  17. Self::Generic {
  18. err: err.to_string(),
  19. }
  20. }
  21. }
  22. impl From<url::ParseError> for CashuError {
  23. fn from(err: url::ParseError) -> Self {
  24. Self::Generic {
  25. err: err.to_string(),
  26. }
  27. }
  28. }
  29. impl From<cashu::error::wallet::Error> for CashuError {
  30. fn from(err: cashu::error::wallet::Error) -> Self {
  31. Self::Generic {
  32. err: err.to_string(),
  33. }
  34. }
  35. }
  36. impl From<ParseOrSemanticError> for CashuError {
  37. fn from(err: ParseOrSemanticError) -> Self {
  38. Self::Generic {
  39. err: err.to_string(),
  40. }
  41. }
  42. }
  43. impl From<cashu::nuts::nut02::Error> for CashuError {
  44. fn from(err: cashu::nuts::nut02::Error) -> Self {
  45. Self::Generic {
  46. err: err.to_string(),
  47. }
  48. }
  49. }
  50. impl From<cashu::url::Error> for CashuError {
  51. fn from(err: cashu::url::Error) -> Self {
  52. Self::Generic {
  53. err: err.to_string(),
  54. }
  55. }
  56. }