Skip to content

Commit

Permalink
cln-plugin: fix over-escaping rpc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 authored and cdecker committed May 15, 2024
1 parent b69609b commit abd1b5f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ where
.send(json!({
"jsonrpc": "2.0",
"id": id,
"error": e.to_string(),
"error": parse_error(e.to_string()),
}))
.await
.context("returning custom error"),
Expand Down Expand Up @@ -895,6 +895,23 @@ pub enum FeatureBitsKind {
Init,
}

#[derive(Clone, serde::Serialize, serde::Deserialize, Debug)]
struct RpcError {
pub code: Option<i32>,
pub message: String,
pub data: Option<serde_json::Value>,
}
fn parse_error(error: String) -> RpcError {
match serde_json::from_str::<RpcError>(&error) {
Ok(o) => o,
Err(_) => RpcError {
code: Some(-32700),
message: error,
data: None,
},
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit abd1b5f

Please sign in to comment.