lnwire: expand FailureMessage. Error() method to include error specific info

This commit is contained in:
Olaoluwa Osuntokun 2017-10-02 21:53:28 -07:00
parent 1057a1a7c3
commit ab4af750e0
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors" "github.com/go-errors/errors"
) )
@ -15,6 +16,7 @@ import (
// failure code. // failure code.
type FailureMessage interface { type FailureMessage interface {
Code() FailCode Code() FailCode
Error() string
} }
// failureMessageLength is the size of the failure message plus the size of // failureMessageLength is the size of the failure message plus the size of
@ -146,9 +148,11 @@ func (c FailCode) String() string {
// NOTE: May be returned by any node in the payment route. // NOTE: May be returned by any node in the payment route.
type FailInvalidRealm struct{} type FailInvalidRealm struct{}
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailInvalidRealm) Error() string { func (f FailInvalidRealm) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// Code returns the failure unique code. // Code returns the failure unique code.
@ -170,9 +174,11 @@ func (f FailTemporaryNodeFailure) Code() FailCode {
return CodeTemporaryNodeFailure return CodeTemporaryNodeFailure
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailTemporaryNodeFailure) Error() string { func (f FailTemporaryNodeFailure) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailPermanentNodeFailure is returned if an otherwise unspecified permanent // FailPermanentNodeFailure is returned if an otherwise unspecified permanent
@ -188,9 +194,11 @@ func (f FailPermanentNodeFailure) Code() FailCode {
return CodePermanentNodeFailure return CodePermanentNodeFailure
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailPermanentNodeFailure) Error() string { func (f FailPermanentNodeFailure) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailRequiredNodeFeatureMissing is returned if a node has requirement // FailRequiredNodeFeatureMissing is returned if a node has requirement
@ -207,9 +215,11 @@ func (f FailRequiredNodeFeatureMissing) Code() FailCode {
return CodeRequiredNodeFeatureMissing return CodeRequiredNodeFeatureMissing
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailRequiredNodeFeatureMissing) Error() string { func (f FailRequiredNodeFeatureMissing) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailPermanentChannelFailure is return if an otherwise unspecified permanent // FailPermanentChannelFailure is return if an otherwise unspecified permanent
@ -225,9 +235,11 @@ func (f FailPermanentChannelFailure) Code() FailCode {
return CodePermanentChannelFailure return CodePermanentChannelFailure
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailPermanentChannelFailure) Error() string { func (f FailPermanentChannelFailure) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailRequiredChannelFeatureMissing is returned if the outgoing channel has a // FailRequiredChannelFeatureMissing is returned if the outgoing channel has a
@ -244,9 +256,11 @@ func (f FailRequiredChannelFeatureMissing) Code() FailCode {
return CodeRequiredChannelFeatureMissing return CodeRequiredChannelFeatureMissing
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailRequiredChannelFeatureMissing) Error() string { func (f FailRequiredChannelFeatureMissing) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailUnknownNextPeer is returned if the next peer specified by the onion is // FailUnknownNextPeer is returned if the next peer specified by the onion is
@ -262,9 +276,11 @@ func (f FailUnknownNextPeer) Code() FailCode {
return CodeUnknownNextPeer return CodeUnknownNextPeer
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailUnknownNextPeer) Error() string { func (f FailUnknownNextPeer) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailUnknownPaymentHash is returned If the payment hash has already been // FailUnknownPaymentHash is returned If the payment hash has already been
@ -282,9 +298,11 @@ func (f FailUnknownPaymentHash) Code() FailCode {
return CodeUnknownPaymentHash return CodeUnknownPaymentHash
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailUnknownPaymentHash) Error() string { func (f FailUnknownPaymentHash) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailIncorrectPaymentAmount is returned if the amount paid is less than the // FailIncorrectPaymentAmount is returned if the amount paid is less than the
@ -303,9 +321,11 @@ func (f FailIncorrectPaymentAmount) Code() FailCode {
return CodeIncorrectPaymentAmount return CodeIncorrectPaymentAmount
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailIncorrectPaymentAmount) Error() string { func (f FailIncorrectPaymentAmount) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailFinalExpiryTooSoon is returned if the cltv_expiry is too low, the final // FailFinalExpiryTooSoon is returned if the cltv_expiry is too low, the final
@ -321,9 +341,11 @@ func (f FailFinalExpiryTooSoon) Code() FailCode {
return CodeFinalExpiryTooSoon return CodeFinalExpiryTooSoon
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailFinalExpiryTooSoon) Error() string { func (f FailFinalExpiryTooSoon) Error() string {
var code = f.Code() return f.Code().String()
return code.String()
} }
// FailInvalidOnionVersion is returned if the onion version byte is unknown. // FailInvalidOnionVersion is returned if the onion version byte is unknown.
@ -334,9 +356,11 @@ type FailInvalidOnionVersion struct {
OnionSHA256 [sha256.Size]byte OnionSHA256 [sha256.Size]byte
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailInvalidOnionVersion) Error() string { func (f FailInvalidOnionVersion) Error() string {
var code = f.Code() return fmt.Sprintf("InvalidOnionVersion(onion_sha=%x)", f.OnionSHA256[:])
return code.String()
} }
// NewInvalidOnionVersion creates new instance of the FailInvalidOnionVersion. // NewInvalidOnionVersion creates new instance of the FailInvalidOnionVersion.
@ -399,9 +423,11 @@ func (f *FailInvalidOnionHmac) Encode(w io.Writer, pver uint32) error {
return writeElement(w, f.OnionSHA256[:]) return writeElement(w, f.OnionSHA256[:])
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailInvalidOnionHmac) Error() string { func (f FailInvalidOnionHmac) Error() string {
var code = f.Code() return fmt.Sprintf("InvalidOnionHMAC(onion_sha=%x)", f.OnionSHA256[:])
return code.String()
} }
// FailInvalidOnionKey is return if the ephemeral key in the onion is // FailInvalidOnionKey is return if the ephemeral key in the onion is
@ -439,9 +465,11 @@ func (f *FailInvalidOnionKey) Encode(w io.Writer, pver uint32) error {
return writeElement(w, f.OnionSHA256[:]) return writeElement(w, f.OnionSHA256[:])
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailInvalidOnionKey) Error() string { func (f FailInvalidOnionKey) Error() string {
var failCode = f.Code() return fmt.Sprintf("InvalidOnionKey(onion_sha=%x)", f.OnionSHA256[:])
return failCode.String()
} }
// FailTemporaryChannelFailure is if an otherwise unspecified transient error // FailTemporaryChannelFailure is if an otherwise unspecified transient error
@ -457,6 +485,9 @@ type FailTemporaryChannelFailure struct {
Update *ChannelUpdate Update *ChannelUpdate
} }
// TODO(roasbeef): any error with an Update needs to include the edge+vertex of
// failure
// NewTemporaryChannelFailure creates new instance of the FailTemporaryChannelFailure. // NewTemporaryChannelFailure creates new instance of the FailTemporaryChannelFailure.
func NewTemporaryChannelFailure(update *ChannelUpdate) *FailTemporaryChannelFailure { func NewTemporaryChannelFailure(update *ChannelUpdate) *FailTemporaryChannelFailure {
return &FailTemporaryChannelFailure{Update: update} return &FailTemporaryChannelFailure{Update: update}
@ -469,9 +500,16 @@ func (f *FailTemporaryChannelFailure) Code() FailCode {
return CodeTemporaryChannelFailure return CodeTemporaryChannelFailure
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailTemporaryChannelFailure) Error() string { func (f FailTemporaryChannelFailure) Error() string {
var code = f.Code() if f.Update == nil {
return code.String() return f.Code().String()
} else {
return fmt.Sprintf("TemporaryChannelFailure(update=%v)",
spew.Sdump(f.Update))
}
} }
// Decode decodes the failure from bytes stream. // Decode decodes the failure from bytes stream.
@ -543,9 +581,12 @@ func (f *FailAmountBelowMinimum) Code() FailCode {
return CodeAmountBelowMinimum return CodeAmountBelowMinimum
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailAmountBelowMinimum) Error() string { func (f FailAmountBelowMinimum) Error() string {
var code = f.Code() return fmt.Sprintf("AmountBelowMinimum(amt=%v, update=%v", f.HtlcMsat,
return code.String() spew.Sdump(f.Update))
} }
// Decode decodes the failure from bytes stream. // Decode decodes the failure from bytes stream.
@ -611,9 +652,12 @@ func (f *FailFeeInsufficient) Code() FailCode {
return CodeFeeInsufficient return CodeFeeInsufficient
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailFeeInsufficient) Error() string { func (f FailFeeInsufficient) Error() string {
var code = f.Code() return fmt.Sprintf("FeeInsufficient(fee=%v, update=%v", f.HtlcMsat,
return code.String() spew.Sdump(f.Update))
} }
// Decode decodes the failure from bytes stream. // Decode decodes the failure from bytes stream.
@ -683,8 +727,8 @@ func (f *FailIncorrectCltvExpiry) Code() FailCode {
} }
func (f *FailIncorrectCltvExpiry) Error() string { func (f *FailIncorrectCltvExpiry) Error() string {
var code = f.Code() return fmt.Sprintf("IncorrectCltvExpiry(expiry=%v, update=%v",
return code.String() f.CltvExpiry, spew.Sdump(f.Update))
} }
// Decode decodes the failure from bytes stream. // Decode decodes the failure from bytes stream.
@ -744,9 +788,11 @@ func (f *FailExpiryTooSoon) Code() FailCode {
return CodeExpiryTooSoon return CodeExpiryTooSoon
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f *FailExpiryTooSoon) Error() string { func (f *FailExpiryTooSoon) Error() string {
var code = f.Code() return fmt.Sprintf("ExpiryTooSoon(update=%v", spew.Sdump(f.Update))
return code.String()
} }
// Decode decodes the failure from l stream. // Decode decodes the failure from l stream.
@ -804,9 +850,12 @@ func (f *FailChannelDisabled) Code() FailCode {
return CodeChannelDisabled return CodeChannelDisabled
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailChannelDisabled) Error() string { func (f FailChannelDisabled) Error() string {
var code = f.Code() return fmt.Sprintf("ChannelDisabled(flags=%v, update=%v", f.Flags,
return code.String() spew.Sdump(f.Update))
} }
// Decode decodes the failure from bytes stream. // Decode decodes the failure from bytes stream.
@ -852,9 +901,11 @@ type FailFinalIncorrectCltvExpiry struct {
CltvExpiry uint32 CltvExpiry uint32
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailFinalIncorrectCltvExpiry) Error() string { func (f FailFinalIncorrectCltvExpiry) Error() string {
var code = f.Code() return fmt.Sprintf("FinalIncorrectCltvExpiry(expiry=%v)", f.CltvExpiry)
return code.String()
} }
// NewFinalIncorrectCltvExpiry creates new instance of the // NewFinalIncorrectCltvExpiry creates new instance of the
@ -895,9 +946,12 @@ type FailFinalIncorrectHtlcAmount struct {
IncomingHTLCAmount MilliSatoshi IncomingHTLCAmount MilliSatoshi
} }
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f FailFinalIncorrectHtlcAmount) Error() string { func (f FailFinalIncorrectHtlcAmount) Error() string {
var code = f.Code() return fmt.Sprintf("FinalIncorrectHtlcAmount(amt=%v)",
return code.String() f.IncomingHTLCAmount)
} }
// NewFinalIncorrectHtlcAmount creates new instance of the // NewFinalIncorrectHtlcAmount creates new instance of the