Skip to content

Commit 5237c0e

Browse files
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.
1 parent ecb4a3f commit 5237c0e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plugins/recklessrpc.c

+17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct reckless {
2828
size_t stderr_read;
2929
size_t stderr_new;
3030
pid_t pid;
31+
char *process_failed;
3132
};
3233

3334
struct lconfig {
@@ -63,6 +64,12 @@ static struct command_result *reckless_result(struct io_conn *conn,
6364
struct reckless *reckless)
6465
{
6566
struct json_stream *response;
67+
if (reckless->process_failed) {
68+
response = jsonrpc_stream_fail(reckless->cmd,
69+
PLUGIN_ERROR,
70+
reckless->process_failed);
71+
return command_finished(reckless->cmd, response);
72+
}
6673
response = jsonrpc_stream_success(reckless->cmd);
6774
json_array_start(response, "result");
6875
const jsmntok_t *results, *result, *logs, *log;
@@ -149,6 +156,15 @@ static struct io_plan *stderr_read_more(struct io_conn *conn,
149156
reckless_send_yes(rkls);
150157
plugin_log(plugin, LOG_DBG, "wrote Y to stdin");
151158
}
159+
/* Old version of reckless installed? */
160+
if (strstr(rkls->stderrbuf, "error: unrecognized arguments: --json")) {
161+
plugin_log(plugin, LOG_DBG, "Reckless call failed due to old "
162+
"installed version.");
163+
rkls->process_failed = tal_strdup(plugin, "The installed "
164+
"reckless utility is out of "
165+
"date. Please update to use "
166+
"the RPC plugin.");
167+
}
152168
return io_read_partial(conn, rkls->stderrbuf + rkls->stderr_read,
153169
tal_count(rkls->stderrbuf) - rkls->stderr_read,
154170
&rkls->stderr_new, stderr_read_more, rkls);
@@ -196,6 +212,7 @@ static struct command_result *reckless_call(struct command *cmd,
196212
reckless->stdout_new = 0;
197213
reckless->stderr_read = 0;
198214
reckless->stderr_new = 0;
215+
reckless->process_failed = NULL;
199216
plugin_log(plugin, LOG_DBG, "calling reckless");
200217
char * full_cmd;
201218
full_cmd = tal_fmt(tmpctx, "calling: [");

0 commit comments

Comments
 (0)