Skip to content

Commit aec0bfa

Browse files
reckless-rpc: 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 1f0973e commit aec0bfa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plugins/recklessrpc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct reckless {
2929
size_t stderr_read;
3030
size_t stderr_new;
3131
pid_t pid;
32+
char *process_failed;
3233
};
3334

3435
struct lconfig {
@@ -62,6 +63,12 @@ static struct command_result *reckless_result(struct io_conn *conn,
6263
struct reckless *reckless)
6364
{
6465
struct json_stream *response;
66+
if (reckless->process_failed) {
67+
response = jsonrpc_stream_fail(reckless->cmd,
68+
PLUGIN_ERROR,
69+
reckless->process_failed);
70+
return command_finished(reckless->cmd, response);
71+
}
6572
response = jsonrpc_stream_success(reckless->cmd);
6673
json_array_start(response, "result");
6774
const jsmntok_t *results, *result, *logs, *log;
@@ -142,6 +149,15 @@ static struct io_plan *stderr_read_more(struct io_conn *conn,
142149
plugin_log(plugin, LOG_DBG, "confirming config creation");
143150
reckless_send_yes(rkls);
144151
}
152+
/* Old version of reckless installed? */
153+
if (strstr(rkls->stderrbuf, "error: unrecognized arguments: --json")) {
154+
plugin_log(plugin, LOG_DBG, "Reckless call failed due to old "
155+
"installed version.");
156+
rkls->process_failed = tal_strdup(plugin, "The installed "
157+
"reckless utility is out of "
158+
"date. Please update to use "
159+
"the RPC plugin.");
160+
}
145161
return io_read_partial(conn, rkls->stderrbuf + rkls->stderr_read,
146162
tal_count(rkls->stderrbuf) - rkls->stderr_read,
147163
&rkls->stderr_new, stderr_read_more, rkls);
@@ -188,6 +204,7 @@ static struct command_result *reckless_call(struct command *cmd,
188204
reckless->stdout_new = 0;
189205
reckless->stderr_read = 0;
190206
reckless->stderr_new = 0;
207+
reckless->process_failed = NULL;
191208
char * full_cmd;
192209
full_cmd = tal_fmt(tmpctx, "calling:");
193210
for (int i=0; i<tal_count(my_call); i++)

0 commit comments

Comments
 (0)