From 51d04e89228876da739d4b832cf555979dfa7ec5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 16 Oct 2017 18:15:46 -0700 Subject: [PATCH] htlcswitch: add new ExtraMsg field to ForwardingError This commit adds a new field to the ForwardingError struct: ExtraMsg. The purpose of this field is to allow the htlcswitch to tack on additional error context to ForwardingError messages returned to the L3 router. --- htlcswitch/failure.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htlcswitch/failure.go b/htlcswitch/failure.go index f066bb0c..0acf7b0a 100644 --- a/htlcswitch/failure.go +++ b/htlcswitch/failure.go @@ -2,6 +2,7 @@ package htlcswitch import ( "bytes" + "fmt" "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/lnwire" @@ -16,9 +17,24 @@ type ForwardingError struct { // of candidate routes in response to the type of error extracted. ErrorSource *btcec.PublicKey + // ExtraMsg is an additional error message that callers can provide in + // order to provide context specific error details. + ExtraMsg string + lnwire.FailureMessage } +// Error implements the built-in error interface. We use this method to allow +// the switch or any callers to insert additional context to the error message +// returned. +func (f *ForwardingError) Error() string { + if f.ExtraMsg == "" { + return f.FailureMessage.Error() + } + + return fmt.Sprintf("%v: %v", f.FailureMessage.Error(), f.ExtraMsg) +} + // ErrorDecrypter is an interface that is used to decrypt the onion encrypted // failure reason an extra out a well formed error. type ErrorDecrypter interface {