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