Skip to content

Commit

Permalink
reckless: catch old installed version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
endothermicdev committed Aug 2, 2024
1 parent 48a776a commit 172129a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions plugins/recklessrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct reckless {
size_t stderr_read;
size_t stderr_new;
pid_t pid;
char *process_failed;
};

struct lconfig {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: [");
Expand Down

0 comments on commit 172129a

Please sign in to comment.