Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [Draft] Add ErrorHandling for LdkServer APIs by G8XSU · Pull Request #19 · lightningdevkit/ldk-server · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use clap::{Parser, Subcommand};
use client::client::LdkNodeServerClient;
use client::error::LdkNodeServerError;
use client::protos::{
use client::protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
use prost::Message;

use crate::error::LdkNodeServerError;
use protos::{
use protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
Expand Down
10 changes: 7 additions & 3 deletions protos/build.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,9 +14,13 @@ fn main() {
fn generate_protos() {
prost_build::Config::new()
.bytes(&["."])
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
.compile_protos(&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"], &["src/proto/"])
.expect("protobuf compilation failed");
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
fs::copy(from_path, "src/lib.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
fs::copy(from_path, "src/api.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
fs::copy(from_path, "src/types.rs").unwrap();
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
fs::copy(from_path, "src/error.rs").unwrap();
}
319 changes: 319 additions & 0 deletions protos/src/api.rs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions protos/src/error.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
/// When HttpStatusCode is not ok (200), the response `content` contains a serialized `ErrorResponse`
/// with the relevant ErrorCode and `message`
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// 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.
#[prost(string, tag="1")]
pub message: ::prost::alloc::string::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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[prost(oneof="error_response::ErrorCode", tags="2, 3, 4, 5, 6")]
pub error_code: ::core::option::Option<error_response::ErrorCode>,
}
/// Nested message and enum types in `ErrorResponse`.
pub mod error_response {
/// 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.
///
/// **Caution**: If a new type of `error_code` is introduced in oneof, `error_code` field will be unset.
/// If unset, it should be treated as `UnknownError`, it will not be set as `UnknownError`.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ErrorCode {
/// Will neve be used as `error_code` by server.
#[prost(message, tag="2")]
UnknownError(super::UnknownError),
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[prost(message, tag="3")]
InvalidRequestError(super::InvalidRequestError),
/// Used when authentication fails or in case of an unauthorized request.
#[prost(message, tag="4")]
AuthError(super::AuthError),
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[prost(message, tag="5")]
LightningError(super::LightningError),
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[prost(message, tag="6")]
InternalServerError(super::InternalServerError),
}
}
/// Will neve be used as `error_code` by server.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct UnknownError {
}
/// Used in the following cases:
/// - The request was missing a required argument.
/// - The specified argument was invalid, incomplete or in the wrong format.
/// - The request body of api cannot be deserialized into corresponding protobuf object.
/// - The request does not follow api contract.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InvalidRequestError {
}
/// Used when authentication fails or in case of an unauthorized request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AuthError {
}
/// Used to represent an Error while doing Lightning operation. Contains `LightningErrorCode` for further details.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LightningError {
#[prost(enumeration="LightningErrorCode", tag="1")]
pub lightning_error_code: i32,
}
/// Used when an internal server error occurred, client is probably at no fault and can safely retry
/// this error with exponential backoff.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct InternalServerError {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LightningErrorCode {
/// Default protobuf Enum value. Will not be used as `LightningErrorCode` by server.
/// **Caution**: If a new Enum value is introduced, it will be seen as `UNKNOWN_LIGHTNING_ERROR` by code using earlier
/// versions of protobuf definition for deserialization.
UnknownLightningError = 0,
/// The requested operation failed, such as invoice creation failed, refund creation failed etc.
OperationFailed = 1,
/// There was a timeout during the requested operation.
OperationTimedOut = 2,
/// Sending a payment has failed.
PaymentSendingFailed = 3,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds = 4,
/// A payment failed since it has already been initiated.
DuplicatePayment = 5,
/// A liquidity request operation failed.
LiquidityRequestFailed = 6,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable = 7,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeHigh = 8,
}
impl LightningErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LightningErrorCode::UnknownLightningError => "UNKNOWN_LIGHTNING_ERROR",
LightningErrorCode::OperationFailed => "OPERATION_FAILED",
LightningErrorCode::OperationTimedOut => "OPERATION_TIMED_OUT",
LightningErrorCode::PaymentSendingFailed => "PAYMENT_SENDING_FAILED",
LightningErrorCode::InsufficientFunds => "INSUFFICIENT_FUNDS",
LightningErrorCode::DuplicatePayment => "DUPLICATE_PAYMENT",
LightningErrorCode::LiquidityRequestFailed => "LIQUIDITY_REQUEST_FAILED",
LightningErrorCode::LiquiditySourceUnavailable => "LIQUIDITY_SOURCE_UNAVAILABLE",
LightningErrorCode::LiquidityFeeHigh => "LIQUIDITY_FEE_HIGH",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_LIGHTNING_ERROR" => Some(Self::UnknownLightningError),
"OPERATION_FAILED" => Some(Self::OperationFailed),
"OPERATION_TIMED_OUT" => Some(Self::OperationTimedOut),
"PAYMENT_SENDING_FAILED" => Some(Self::PaymentSendingFailed),
"INSUFFICIENT_FUNDS" => Some(Self::InsufficientFunds),
"DUPLICATE_PAYMENT" => Some(Self::DuplicatePayment),
"LIQUIDITY_REQUEST_FAILED" => Some(Self::LiquidityRequestFailed),
"LIQUIDITY_SOURCE_UNAVAILABLE" => Some(Self::LiquiditySourceUnavailable),
"LIQUIDITY_FEE_HIGH" => Some(Self::LiquidityFeeHigh),
_ => None,
}
}
}
Loading