Source: libjson-rpc-perl Source-Version: 1.06-3 Severity: wishlist Tags: patch upstream
Hi! When running the kgb-client (from kgb-bot), if the server returns an error, then the JSON::RPC::Legacy::Client module will try to parse a non-existent JSON reply, which then ends up as a truncated and confusing error message, such as: remote: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "Can't connect to kgb...") at /usr/share/perl5/JSON/RPC/Legacy/Client.pm line 186. remote: Unable to relay message. All servers failed With the attached patch, the error message is instead something like: remote: Transport error: 500 Can't connect to kgb.tina.pm:9418 (Network is unreachable) remote: Unable to relay message. All servers failed I think this would fix the kgb-bot bug #798813. Thanks, Guillem
From fc84cb2df7ef9cbc33f6fc03975b3a96f34bb9ff Mon Sep 17 00:00:00 2001 From: Guillem Jover <guil...@hadrons.org> Date: Sun, 21 Jul 2024 23:27:16 +0200 Subject: [PATCH] JSON::RPC::Legacy::Client: Do not try to parse non-existing JSON If the server reported a server error, then we get no JSON. We should return immediately instead of trying to parse the non-existing JSON, otherwise the callers will get confusing and truncated errors. --- lib/JSON/RPC/Legacy/Client.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/JSON/RPC/Legacy/Client.pm b/lib/JSON/RPC/Legacy/Client.pm index b389c81..404a3f2 100644 --- a/lib/JSON/RPC/Legacy/Client.pm +++ b/lib/JSON/RPC/Legacy/Client.pm @@ -107,6 +107,9 @@ sub call { $self->status_line($result->status_line); + # If the server returned an error, we have no JSON. + return if ($result->code >= 500 && $result->code < 600); + return unless($result->content); # notification? if ($service) { -- 2.45.2