From b2a5cf422ffe8b4b5115972c2837b8beabf57a82 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 4 Dec 2020 13:30:10 +0100 Subject: [PATCH] jsonrpc: Forward errors on malformed requests to cli We were masquerading errors when parsing the request by reporting only a bogus malformed `id` field in the response, when the real issue was that we were unable to parse the request in the first place (which caused the null-id error to be returned). Fixes #4238 --- cli/lightning-cli.c | 5 +++-- lightningd/jsonrpc.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index 16852e749..37f221e35 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -823,8 +823,9 @@ int main(int argc, char *argv[]) "Missing 'id' in response '%s'", resp); if (!json_tok_streq(resp, id, idstr)) errx(ERROR_TALKING_TO_LIGHTNINGD, - "Incorrect 'id' in response: %.*s", - json_tok_full_len(id), json_tok_full(resp, id)); + "Incorrect 'id' (%.*s) in response: %.*s", + json_tok_full_len(id), json_tok_full(resp, id), + json_tok_full_len(toks), json_tok_full(resp, toks)); if (!error || json_tok_is_null(resp, error)) { switch (format) { diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 37a8ec4b9..585fa4014 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -956,8 +956,10 @@ static struct io_plan *read_json(struct io_conn *conn, if (!json_parse_input(&jcon->input_parser, &jcon->input_toks, jcon->buffer, jcon->used, &complete)) { - json_command_malformed(jcon, "null", - "Invalid token in json input"); + json_command_malformed( + jcon, "null", + tal_fmt(tmpctx, "Invalid token in json input: '%s'", + tal_strndup(tmpctx, jcon->buffer, jcon->used))); return io_halfclose(conn); }