From 5237c0e5d22b45b0257fda328d7b8334f11cc2b5 Mon Sep 17 00:00:00 2001 From: Alex Myers Date: Thu, 1 Aug 2024 17:05:36 -0500 Subject: [PATCH] reckless: catch old installed version If the rpc plugin is run while an older version of reckless is found on PATH, it produces an error: 2024-08-01T18:32:00.849Z DEBUG plugin-recklessrpc: reckless-stderr:usage: reckless [-h] [-d RECKLESS_DIR] [-l LIGHTNING] [-c CONF] [-r] [--network NETWORK] [-v] {install,uninstall,search,enable,disable,source,help} ... reckless: error: unrecognized arguments: --json Catch this and don't try to parse the output as json. --- plugins/recklessrpc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/recklessrpc.c b/plugins/recklessrpc.c index 71f52d63fc10..344b9cf05afa 100644 --- a/plugins/recklessrpc.c +++ b/plugins/recklessrpc.c @@ -28,6 +28,7 @@ struct reckless { size_t stderr_read; size_t stderr_new; pid_t pid; + char *process_failed; }; struct lconfig { @@ -63,6 +64,12 @@ static struct command_result *reckless_result(struct io_conn *conn, struct reckless *reckless) { struct json_stream *response; + if (reckless->process_failed) { + response = jsonrpc_stream_fail(reckless->cmd, + PLUGIN_ERROR, + reckless->process_failed); + return command_finished(reckless->cmd, response); + } response = jsonrpc_stream_success(reckless->cmd); json_array_start(response, "result"); const jsmntok_t *results, *result, *logs, *log; @@ -149,6 +156,15 @@ static struct io_plan *stderr_read_more(struct io_conn *conn, reckless_send_yes(rkls); plugin_log(plugin, LOG_DBG, "wrote Y to stdin"); } + /* Old version of reckless installed? */ + if (strstr(rkls->stderrbuf, "error: unrecognized arguments: --json")) { + plugin_log(plugin, LOG_DBG, "Reckless call failed due to old " + "installed version."); + rkls->process_failed = tal_strdup(plugin, "The installed " + "reckless utility is out of " + "date. Please update to use " + "the RPC plugin."); + } return io_read_partial(conn, rkls->stderrbuf + rkls->stderr_read, tal_count(rkls->stderrbuf) - rkls->stderr_read, &rkls->stderr_new, stderr_read_more, rkls); @@ -196,6 +212,7 @@ static struct command_result *reckless_call(struct command *cmd, reckless->stdout_new = 0; reckless->stderr_read = 0; reckless->stderr_new = 0; + reckless->process_failed = NULL; plugin_log(plugin, LOG_DBG, "calling reckless"); char * full_cmd; full_cmd = tal_fmt(tmpctx, "calling: [");