-
Notifications
You must be signed in to change notification settings - Fork 13
Use LdkServerError for error handling in all APIs. #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2fb0278
Derive traits for LdkServerError.
G8XSU 87e6c01
Implement Display & std::Error for LdkServerError.
G8XSU 5389155
Add constructor for LdkServerError.
G8XSU 0e9181b
Return LdkServerError from NodeService.
G8XSU 221116f
Return LdkServerError from GetNodeInfo API.
G8XSU 88095eb
Return LdkServerError from GetBalances API.
G8XSU 8dd2ae0
Impl from<NodeError> for LdkServerError.
G8XSU 3b8c96b
Return LdkServerError from OnchainReceive API.
G8XSU d43f9f0
Return LdkServerError from OnchainSend API.
G8XSU 5c08b42
Return LdkServerError from Bolt11Receive API.
G8XSU bc0cb45
Return LdkServerError from Bolt11Send API.
G8XSU 8aa6bde
Return LdkServerError from Bolt12Receive API.
G8XSU 403941b
Return LdkServerError from Bolt12Send API.
G8XSU d6cc6d9
Return LdkServerError from OpenChannel API.
G8XSU 029a28d
Return LdkServerError from CloseChannel API.
G8XSU cd91495
Return LdkServerError from ListChannels API.
G8XSU f8015cd
Return LdkServerError from UpdateChannelConfig API.
G8XSU 6e25671
Return LdkServerError from GetPaymentDetails API.
G8XSU ba5bf69
Return LdkServerError from ListPayments API.
G8XSU 9b4adee
Return LdkServerError from ListForwardedPayments API.
G8XSU b4f20f5
Initialize vec with capacity, to pre-allocate space.
G8XSU db54e65
Return protobuf serialized ErrorResponse from APIs.
G8XSU 605b23f
Add ErrorResponse handling in client.
G8XSU f795976
Add ErrorResponse handling in cli.
G8XSU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,62 @@ | ||
use prost::DecodeError; | ||
use std::fmt; | ||
|
||
/// When there is an error in request to LDK Server, the response contains a relevant error code. | ||
#[derive(Debug)] | ||
pub enum LdkServerError { | ||
/// There is an unknown error. (Placeholder until error handling is done.) | ||
InternalError(String), | ||
/// Represents an error returned by the LDK server. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct LdkServerError { | ||
/// The error message containing a generic description of the error condition in English. | ||
/// It is intended for a human audience only and should not be parsed to extract any information | ||
/// programmatically. Client-side code may use it for logging only. | ||
pub message: String, | ||
|
||
/// The error code uniquely identifying an error condition. | ||
/// It is meant to be read and understood programmatically by code that detects/handles errors by | ||
/// type. | ||
pub error_code: LdkServerErrorCode, | ||
} | ||
|
||
impl LdkServerError { | ||
/// Creates a new [`LdkServerError`] with the given error code and message. | ||
pub fn new(error_code: LdkServerErrorCode, message: impl Into<String>) -> Self { | ||
Self { error_code, message: message.into() } | ||
} | ||
} | ||
|
||
impl From<DecodeError> for LdkServerError { | ||
fn from(err: DecodeError) -> Self { | ||
LdkServerError::InternalError(err.to_string()) | ||
impl std::error::Error for LdkServerError {} | ||
|
||
impl fmt::Display for LdkServerError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "Error: [{}]: {}", self.error_code, self.message) | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for LdkServerError { | ||
fn from(err: reqwest::Error) -> Self { | ||
LdkServerError::InternalError(err.to_string()) | ||
/// Defines error codes for categorizing LDK server errors. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub enum LdkServerErrorCode { | ||
/// Please refer to [`ldk_server_protos::error::ErrorCode::InvalidRequestError`]. | ||
InvalidRequestError, | ||
|
||
/// Please refer to [`ldk_server_protos::error::ErrorCode::AuthError`]. | ||
AuthError, | ||
|
||
/// Please refer to [`ldk_server_protos::error::ErrorCode::LightningError`]. | ||
LightningError, | ||
|
||
/// Please refer to [`ldk_server_protos::error::ErrorCode::InternalServerError`]. | ||
InternalServerError, | ||
|
||
/// There is an unknown error, it could be a client-side bug, unrecognized error-code, network error | ||
/// or something else. | ||
InternalError, | ||
} | ||
|
||
impl fmt::Display for LdkServerErrorCode { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
LdkServerErrorCode::InvalidRequestError => write!(f, "InvalidRequestError"), | ||
LdkServerErrorCode::AuthError => write!(f, "AuthError"), | ||
LdkServerErrorCode::LightningError => write!(f, "LightningError"), | ||
LdkServerErrorCode::InternalServerError => write!(f, "InternalServerError"), | ||
LdkServerErrorCode::InternalError => write!(f, "InternalError"), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked through these exhaustively, but for BOLT11
DuplicatePayment
is returned if the user tries to pay an invoice with the same payment hash twice. So shouldn't it map to anInvalidRequestError
? Though for BOLT12 it would happen if we randomly generate the same payment id, which shouldn't happen.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't mark
DuplicatePayment
as invalid-request with certainty, it could be a legitimate race-condition on client side or idempotency failure.Ideally, DuplicatePayment should become a sub-error within the lightning error category.
We typically use invalid-request for requests that can be safely ignored or can’t be fixed programmatically, but
DuplicatePayment
might indicate a successful payment the client didn’t register.