Skip to main content

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    /// Amount Error
10    #[error(transparent)]
11    Amount(#[from] cdk_common::amount::Error),
12    /// Invoice amount not defined
13    #[error("Unknown invoice amount")]
14    UnknownInvoiceAmount,
15    /// Unknown invoice
16    #[error("Unknown invoice")]
17    UnknownInvoice,
18    /// Connection error
19    #[error("LND connection error")]
20    Connection,
21    /// Invalid hash
22    #[error("Invalid hash")]
23    InvalidHash,
24    /// Payment failed
25    #[error("LND payment failed")]
26    PaymentFailed,
27    /// Payment dispatch outcome is indeterminate
28    ///
29    /// Returned when a `send_*` call or its status stream fails at the
30    /// dispatch boundary: LND may or may not have accepted the payment. This
31    /// is deliberately distinct from [`Error::PaymentFailed`], which is only
32    /// constructed after every route retry ended in a definitive no-route
33    /// result (i.e. pre-dispatch). Backends must keep this variant out of the
34    /// terminal-failure classifier so the melt stays indeterminate.
35    #[error("LND payment dispatch outcome is indeterminate")]
36    AmbiguousDispatch,
37    /// Unknown payment status
38    #[error("LND unknown payment status")]
39    UnknownPaymentStatus,
40    /// Missing last hop in route
41    #[error("LND missing last hop in route")]
42    MissingLastHop,
43    /// No route found
44    #[error("No route found")]
45    NoRoute,
46    /// Amount overflow
47    #[error("Amount overflow")]
48    AmountOverflow,
49    /// Errors coming from the backend
50    #[error("LND error: `{0}`")]
51    LndError(Status),
52    /// Errors invalid config
53    #[error("LND invalid config: `{0}`")]
54    InvalidConfig(String),
55    /// Could not read file
56    #[error("Could not read file")]
57    ReadFile,
58    /// Database Error
59    #[error("Database error: {0}")]
60    Database(String),
61}
62
63impl From<Error> for cdk_common::payment::Error {
64    fn from(e: Error) -> Self {
65        Self::Backend(Box::new(e))
66    }
67}