Skip to content

Commit

Permalink
lnwire: return more descriptive errors in DecodeFailure for onion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Sep 12, 2017
1 parent 67aa519 commit 1e5949c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lnwire/onion_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,16 @@ func DecodeFailure(r io.Reader, pver uint32) (FailureMessage, error) {
// is a 2 byte length followed by the payload itself.
var failureLength uint16
if err := readElement(r, &failureLength); err != nil {
return nil, err
return nil, fmt.Errorf("unable to read error len: %v", err)
}
if failureLength > failureMessageLength {
return nil, fmt.Errorf("failure message is too "+
"long: %v", failureLength)
}
failureData := make([]byte, failureLength)
if _, err := io.ReadFull(r, failureData); err != nil {
return nil, err
return nil, fmt.Errorf("unable to full read payload of "+
"%v: %v", failureLength, err)
}

dataReader := bytes.NewReader(failureData)
Expand All @@ -848,23 +849,24 @@ func DecodeFailure(r io.Reader, pver uint32) (FailureMessage, error) {
// the first two bytes of the buffer.
var codeBytes [2]byte
if _, err := io.ReadFull(dataReader, codeBytes[:]); err != nil {
return nil, err
return nil, fmt.Errorf("unable to read failure code: %v", err)
}
failCode := FailCode(binary.BigEndian.Uint16(codeBytes[:]))

// Create the empty failure by given code and populate the failure with
// additional data if needed.
failure, err := makeEmptyOnionError(failCode)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to make empty error: %v", err)
}

// Finally, if this failure has a payload, then we'll read that now as
// well.
switch f := failure.(type) {
case Serializable:
if err := f.Decode(dataReader, pver); err != nil {
return nil, err
return nil, fmt.Errorf("unable to decode error "+
"update: %v", err)
}
}

Expand Down

0 comments on commit 1e5949c

Please sign in to comment.