cdk_lnd/
error.rs

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