From 4f287d10d7e8019a64e2ab58c884edb484877fe7 Mon Sep 17 00:00:00 2001 From: Edward Houston Date: Fri, 12 Jun 2026 10:25:51 +0200 Subject: [PATCH] fix(electrum): return JSON-RPC error for unknown methods instead of dropping the connection The catch-all arm in handle_command used bail!, which returns Err from the whole function and bypasses the error-to-JSON conversion below it. The error then propagated out of handle_replies and run() shut the socket down, so any unknown method (including methods compiled out by feature flags, like scripthash.get_balance on Liquid builds) closed the connection with no reply, and a single unknown method inside a batch killed the entire batch. Produce the error as a value inside 'result' instead, so it is returned as a normal JSON-RPC error reply and the connection stays open. The method's params are no longer echoed back in the error message. --- src/electrum/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/electrum/server.rs b/src/electrum/server.rs index 873a8dc20..43189551c 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -474,10 +474,10 @@ impl Connection { #[cfg(feature = "electrum-discovery")] "server.add_peer" => self.server_add_peer(¶ms), - &_ => bail!("unknown method {} {:?}", method, params), + &_ => Err(format!("unknown method {}", method).into()), }; timer.observe_duration(); - // TODO: return application errors should be sent to the client + // TODO: return errors as JSON-RPC 2.0 error objects ({code, message}) instead of bare strings Ok(match result { Ok(result) => json!({"jsonrpc": "2.0", "id": id, "result": result}), Err(e) => {