1 package wire
2 3 import (
4 "fmt"
5 )
6 7 // MessageError describes an issue with a message. An example of some potential issues are messages from the wrong
8 // bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads. This provides a mechanism for
9 // the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that
10 // resulted from malformed messages.
11 type MessageError struct {
12 Func string // Function name
13 Description string // Human readable description of the issue
14 }
15 16 // Error satisfies the error interface and prints human-readable errors.
17 func (e *MessageError) Error() string {
18 if e.Func != "" {
19 return fmt.Sprintf("%v: %v", e.Func, e.Description)
20 }
21 return e.Description
22 }
23 24 // messageError creates an error for the given function and description.
25 func messageError(f string, desc string) *MessageError {
26 return &MessageError{Func: f, Description: desc}
27 }
28