lnwire+multi: define Error() for lnwire.Error
To make lnwire.Error actually satisfy the error interface, define the Error method directly.
This commit is contained in:
5 files changed
+41
-34
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -87,6 +88,18 @@ func NewError() *Error {
|
||||
// interface.
|
||||
var _ Message = (*Error)(nil)
|
||||
|
||||
// Error returns the string representation to Error.
|
||||
//
|
||||
// NOTE: Satisfies the error interface.
|
||||
func (c *Error) Error() string {
|
||||
errMsg := "non-ascii data"
|
||||
if isASCII(c.Data) {
|
||||
errMsg = string(c.Data)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("chan_id=%v, err=%v", c.ChanID, errMsg)
|
||||
}
|
||||
|
||||
// Decode deserializes a serialized Error message stored in the passed
|
||||
// io.Reader observing the specified protocol version.
|
||||
//
|
||||
@@ -125,3 +138,14 @@ func (c *Error) MaxPayloadLength(uint32) uint32 {
|
||||
// 32 + 2 + 65501
|
||||
return 65535
|
||||
}
|
||||
|
||||
// isASCII is a helper method that checks whether all bytes in `data` would be
|
||||
// printable ASCII characters if interpreted as a string.
|
||||
func isASCII(data []byte) bool {
|
||||
for _, c := range data {
|
||||
if c < 32 || c > 126 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in new issue
Block a user