2015-01-31 19:32:55 +01:00
|
|
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
2013-05-10 03:56:03 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-31 19:32:55 +01:00
|
|
|
package wire
|
2013-05-10 03:56:03 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MessageError describes an issue with a message.
|
|
|
|
// An example of some potential issues are messages from the wrong bitcoin
|
|
|
|
// network, invalid commands, mismatched checksums, and exceeding max payloads.
|
|
|
|
//
|
|
|
|
// This provides a mechanism for the caller to type assert the error to
|
|
|
|
// differentiate between general io errors such as io.EOF and issues that
|
|
|
|
// resulted from malformed messages.
|
|
|
|
type MessageError struct {
|
|
|
|
Func string // Function name
|
|
|
|
Description string // Human readable description of the issue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error satisfies the error interface and prints human-readable errors.
|
|
|
|
func (e *MessageError) Error() string {
|
|
|
|
if e.Func != "" {
|
|
|
|
return fmt.Sprintf("%v: %v", e.Func, e.Description)
|
|
|
|
}
|
|
|
|
return e.Description
|
|
|
|
}
|
|
|
|
|
|
|
|
// messageError creates an error for the given function and description.
|
|
|
|
func messageError(f string, desc string) *MessageError {
|
|
|
|
return &MessageError{Func: f, Description: desc}
|
|
|
|
}
|