param: make command sinks (fail/success) return a special type.

These routines free the 'struct command': a common coding error is not
to return immediately.

To catch this, we make them return a non-NULL 'struct command_result
*', and we're going to make the command handlers return the same (to
encourage 'return command_fail(...)'-style usage).

We also provide two sources for external use:
1. command_param_failed() when param() fails.
2. command_its_complicated() for some complex cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-12-16 15:19:06 +10:30
parent 12731c4a60
commit 93bf7c4839
6 changed files with 90 additions and 25 deletions

View File

@@ -22,13 +22,15 @@ static bool check_fail(void) {
struct command *cmd;
void command_fail(struct command *cmd, int code, const char *fmt, ...)
struct command_result *command_fail(struct command *cmd,
int code, const char *fmt, ...)
{
failed = true;
va_list ap;
va_start(ap, fmt);
fail_msg = tal_vfmt(cmd, fmt, ap);
va_end(ap);
return NULL;
}
/* AUTOGENERATED MOCKS START */