diff --git a/doc/lightning-invoice.7 b/doc/lightning-invoice.7
index 7979f64e2..de503eef7 100644
--- a/doc/lightning-invoice.7
+++ b/doc/lightning-invoice.7
@@ -2,12 +2,12 @@
.\" Title: lightning-invoice
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1
-.\" Date: 04/23/2018
+.\" Date: 04/26/2018
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "LIGHTNING\-INVOICE" "7" "04/23/2018" "\ \&" "\ \&"
+.TH "LIGHTNING\-INVOICE" "7" "04/26/2018" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -50,6 +50,45 @@ The \fIpreimage\fR is a 64\-digit hex string to be used as payment preimage for
.SH "RETURN VALUE"
.sp
On success, a hash is returned as \fIpayment_hash\fR to be given to the payer, and the \fIexpiry_time\fR as a UNIX timestamp\&. It also returns a BOLT11 invoice as \fIbolt11\fR to be given to the payer\&. On failure, an error is returned and no invoice is created\&. If the lightning process fails before responding, the caller should use lightning\-listinvoice(7) to query whether this invoice was created or not\&.
+.sp
+The following error codes may occur:
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+\-1\&. Catchall nonspecific error\&.
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+900\&. An invoice with the given
+\fIlabel\fR
+already exists\&.
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+901\&. An invoice with the given
+\fIpreimage\fR
+already exists\&.
+.RE
.SH "AUTHOR"
.sp
Rusty Russell is mainly responsible\&.
diff --git a/doc/lightning-invoice.7.txt b/doc/lightning-invoice.7.txt
index e64e540ab..b6bc1fd9d 100644
--- a/doc/lightning-invoice.7.txt
+++ b/doc/lightning-invoice.7.txt
@@ -59,7 +59,11 @@ On failure, an error is returned and no invoice is created. If the
lightning process fails before responding, the caller should use
lightning-listinvoice(7) to query whether this invoice was created or not.
-//FIXME:Enumerate errors
+The following error codes may occur:
+
+* -1. Catchall nonspecific error.
+* 900. An invoice with the given 'label' already exists.
+* 901. An invoice with the given 'preimage' already exists.
AUTHOR
------
diff --git a/lightningd/invoice.c b/lightningd/invoice.c
index 3b016a619..6f4253a40 100644
--- a/lightningd/invoice.c
+++ b/lightningd/invoice.c
@@ -16,6 +16,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -203,7 +204,9 @@ static void json_invoice(struct command *cmd,
return;
}
if (wallet_invoice_find_by_label(wallet, &invoice, label_val)) {
- command_fail(cmd, "Duplicate label '%s'", label_val->s);
+ command_fail_detailed(cmd, INVOICE_LABEL_ALREADY_EXISTS,
+ NULL,
+ "Duplicate label '%s'", label_val->s);
return;
}
if (strlen(label_val->s) > INVOICE_MAX_LABEL_LEN) {
@@ -303,7 +306,8 @@ static void json_invoice(struct command *cmd,
*/
if (preimagetok &&
wallet_invoice_find_by_rhash(cmd->ld->wallet, &invoice, &rhash)) {
- command_fail(cmd, "preimage already used");
+ command_fail_detailed(cmd, INVOICE_PREIMAGE_ALREADY_EXISTS,
+ NULL, "preimage already used");
return;
}
diff --git a/lightningd/jsonrpc_errors.h b/lightningd/jsonrpc_errors.h
index b52e0b4d5..9312eb8de 100644
--- a/lightningd/jsonrpc_errors.h
+++ b/lightningd/jsonrpc_errors.h
@@ -23,4 +23,8 @@
#define PAY_UNSPECIFIED_ERROR 209
#define PAY_STOPPED_RETRYING 210
+/* Errors from `invoice` command */
+#define INVOICE_LABEL_ALREADY_EXISTS 900
+#define INVOICE_PREIMAGE_ALREADY_EXISTS 901
+
#endif /* LIGHTNING_LIGHTNINGD_JSONRPC_ERRORS_H */