errors.go 1.3 KB

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