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