common: move now-enlarged command_fail_badparam into its own source file.

It's getting a bit awkward to inline now: it's non-trivial.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-06-24 13:15:50 +09:30
parent f33c5188ef
commit 9fd29d35dd
16 changed files with 118 additions and 102 deletions

33
common/json_command.c Normal file
View File

@@ -0,0 +1,33 @@
#include "config.h"
#include <common/json_command.h>
struct command_result *
command_fail_badparam(struct command *cmd,
const char *paramname,
const char *buffer,
const jsmntok_t *tok,
const char *msg)
{
if (command_dev_apis(cmd)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"%s: %s: invalid token '%.*s'",
paramname, msg,
json_tok_full_len(tok),
json_tok_full(buffer, tok));
}
/* Someone misconfigured LNBITS with "" around the rune, and so the
* user got a message about a bad rune parameter which *contained the
* rune itself*!. LNBITS should probably swallow any JSONRPC2_* error
* itself, but it is quite possibly not the only case where this case
* where this can happen. So we are a little circumspect in this
* case. */
command_log(cmd, LOG_INFORM,
"Invalid parameter %s (%s): token '%.*s'",
paramname, msg,
json_tok_full_len(tok),
json_tok_full(buffer, tok));
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"%s: %s: invalid token (see logs for details)",
paramname, msg);
}