Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightningd/invoice.c: Improve programmatic error reporting for delinvoice. #3853

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/jsonrpc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ static const errcode_t CONNECT_ALL_ADDRESSES_FAILED = 401;
/* bitcoin-cli plugin errors */
#define BCLI_ERROR 400

/* Errors from `invoice` command */
/* Errors from `invoice` or `delinvoice` commands */
static const errcode_t INVOICE_LABEL_ALREADY_EXISTS = 900;
static const errcode_t INVOICE_PREIMAGE_ALREADY_EXISTS = 901;
static const errcode_t INVOICE_HINTS_GAVE_NO_ROUTES = 902;
static const errcode_t INVOICE_EXPIRED_DURING_WAIT = 903;
static const errcode_t INVOICE_WAIT_TIMED_OUT = 904;
static const errcode_t INVOICE_NOT_FOUND = 905;
static const errcode_t INVOICE_STATUS_UNEXPECTED = 906;

/* Errors from HSM crypto operations. */
static const errcode_t HSM_ECDH_FAILED = 800;
Expand Down
15 changes: 15 additions & 0 deletions doc/lightning-delinvoice.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions doc/lightning-delinvoice.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ RETURN VALUE
On success, an invoice description will be returned as per
lightning-listinvoice(7).

ERRORS
------

The following errors may be reported:

- -1: Database error.
- 905: An invoice with that label does not exist.
- 906: The invoice *status* does not match the parameter.
An error object will be returned as error *data*, containing
*current_status* and *expected_status* fields.
This is most likely due to the *status* of the invoice
changing just before this command is invoked.

AUTHOR
------

Expand Down
15 changes: 11 additions & 4 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ static struct command_result *json_delinvoice(struct command *cmd,
return command_param_failed();

if (!wallet_invoice_find_by_label(wallet, &i, label)) {
return command_fail(cmd, LIGHTNINGD, "Unknown invoice");
return command_fail(cmd, INVOICE_NOT_FOUND, "Unknown invoice");
}

details = wallet_invoice_details(cmd, cmd->ld->wallet, i);
Expand All @@ -1136,15 +1136,22 @@ static struct command_result *json_delinvoice(struct command *cmd,
* might not make sense if it changed! */
actual_status = invoice_status_str(details);
if (!streq(actual_status, status)) {
return command_fail(cmd, LIGHTNINGD,
"Invoice status is %s not %s",
actual_status, status);
struct json_stream *js;
js = json_stream_fail(cmd, INVOICE_STATUS_UNEXPECTED,
tal_fmt(tmpctx,
"Invoice status is %s not %s",
actual_status, status));
json_add_string(js, "current_status", actual_status);
json_add_string(js, "expected_status", status);
json_object_end(js);
return command_failed(cmd, js);
}

if (!wallet_invoice_delete(wallet, i)) {
log_broken(cmd->ld->log,
"Error attempting to remove invoice %"PRIu64,
i.id);
/* FIXME: allocate a generic DATABASE_ERROR code. */
return command_fail(cmd, LIGHTNINGD, "Database error");
}

Expand Down