| 42 | }; |
| 43 | |
| 44 | static struct command_result *WARN_UNUSED_RESULT |
| 45 | fail_invreq_level(struct command *cmd, |
| 46 | const struct invreq *invreq, |
| 47 | enum log_level l, |
| 48 | const char *fmt, va_list ap) |
| 49 | { |
| 50 | char *full_fmt, *msg; |
| 51 | struct tlv_onionmsg_tlv *payload; |
| 52 | struct tlv_invoice_error *err; |
| 53 | |
| 54 | full_fmt = tal_fmt(tmpctx, "Failed invreq"); |
| 55 | if (invreq->invreq) { |
| 56 | tal_append_fmt(&full_fmt, " %s", |
| 57 | invrequest_encode(tmpctx, invreq->invreq)); |
| 58 | } |
| 59 | tal_append_fmt(&full_fmt, ": %s", fmt); |
| 60 | |
| 61 | msg = tal_vfmt(tmpctx, full_fmt, ap); |
| 62 | plugin_log(cmd->plugin, l, "%s", msg); |
| 63 | |
| 64 | /* Don't send back internal error details. */ |
| 65 | if (l == LOG_BROKEN) |
| 66 | msg = "Internal error"; |
| 67 | |
| 68 | err = tlv_invoice_error_new(cmd); |
| 69 | /* Remove NUL terminator */ |
| 70 | err->error = tal_dup_arr(err, char, msg, strlen(msg), 0); |
| 71 | /* FIXME: Add suggested_value / erroneous_field! */ |
| 72 | |
| 73 | if (!invreq->reply_path) |
| 74 | return command_hook_success(cmd); |
| 75 | |
| 76 | payload = tlv_onionmsg_tlv_new(tmpctx); |
| 77 | payload->invoice_error = tal_arr(payload, u8, 0); |
| 78 | towire_tlv_invoice_error(&payload->invoice_error, err); |
| 79 | return send_onion_reply(cmd, invreq->reply_path, payload); |
| 80 | } |
| 81 | |
| 82 | static struct command_result *WARN_UNUSED_RESULT PRINTF_FMT(3,4) |
| 83 | fail_invreq(struct command *cmd, |
no test coverage detected