github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/wire/error.go (about)

     1  // Copyright (c) 2013-2015 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package wire
     7  
     8  import (
     9  	"fmt"
    10  )
    11  
    12  // MessageError describes an issue with a message.
    13  // An example of some potential issues are messages from the wrong bitcoin
    14  // network, invalid commands, mismatched checksums, and exceeding max payloads.
    15  //
    16  // This provides a mechanism for the caller to type assert the error to
    17  // differentiate between general io errors such as io.EOF and issues that
    18  // resulted from malformed messages.
    19  type MessageError struct {
    20  	Func        string // Function name
    21  	Description string // Human readable description of the issue
    22  }
    23  
    24  // Error satisfies the error interface and prints human-readable errors.
    25  func (e *MessageError) Error() string {
    26  	if e.Func != "" {
    27  		return fmt.Sprintf("%v: %v", e.Func, e.Description)
    28  	}
    29  	return e.Description
    30  }
    31  
    32  // messageError creates an error for the given function and description.
    33  func messageError(f string, desc string) *MessageError {
    34  	return &MessageError{Func: f, Description: desc}
    35  }