github.com/nsqio/nsq@v1.3.0/internal/protocol/errors.go (about)

     1  package protocol
     2  
     3  type ChildErr interface {
     4  	Parent() error
     5  }
     6  
     7  // ClientErr provides a way for NSQ daemons to log a human reabable
     8  // error string and return a machine readable string to the client.
     9  //
    10  // see docs/protocol.md for error codes by command
    11  type ClientErr struct {
    12  	ParentErr error
    13  	Code      string
    14  	Desc      string
    15  }
    16  
    17  // Error returns the machine readable form
    18  func (e *ClientErr) Error() string {
    19  	return e.Code + " " + e.Desc
    20  }
    21  
    22  // Parent returns the parent error
    23  func (e *ClientErr) Parent() error {
    24  	return e.ParentErr
    25  }
    26  
    27  // NewClientErr creates a ClientErr with the supplied human and machine readable strings
    28  func NewClientErr(parent error, code string, description string) *ClientErr {
    29  	return &ClientErr{parent, code, description}
    30  }
    31  
    32  type FatalClientErr struct {
    33  	ParentErr error
    34  	Code      string
    35  	Desc      string
    36  }
    37  
    38  // Error returns the machine readable form
    39  func (e *FatalClientErr) Error() string {
    40  	return e.Code + " " + e.Desc
    41  }
    42  
    43  // Parent returns the parent error
    44  func (e *FatalClientErr) Parent() error {
    45  	return e.ParentErr
    46  }
    47  
    48  // NewClientErr creates a ClientErr with the supplied human and machine readable strings
    49  func NewFatalClientErr(parent error, code string, description string) *FatalClientErr {
    50  	return &FatalClientErr{parent, code, description}
    51  }