-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy patherrors.go
97 lines (80 loc) · 2.33 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package nsq
import (
"bytes"
"errors"
"fmt"
"strings"
)
var (
FailedOnNotLeader = "E_FAILED_ON_NOT_LEADER"
FailedOnNotLeaderBytes = []byte("E_FAILED_ON_NOT_LEADER")
E_TOPIC_NOT_EXIST = "E_TOPIC_NOT_EXIST"
E_TOPIC_NOT_EXIST_BYTES = []byte("E_TOPIC_NOT_EXIST")
FailedOnNotWritable = "E_FAILED_ON_NOT_WRITABLE"
FailedOnNotWritableBytes = []byte("E_FAILED_ON_NOT_WRITABLE")
)
func IsFailedOnNotLeader(err error) bool {
if err != nil {
return strings.HasPrefix(err.Error(), FailedOnNotLeader)
}
return false
}
func IsFailedOnNotWritable(err error) bool {
if err != nil {
return strings.HasPrefix(err.Error(), FailedOnNotWritable)
}
return false
}
func IsTopicNotExist(err error) bool {
if err != nil {
return strings.HasPrefix(err.Error(), E_TOPIC_NOT_EXIST)
}
return false
}
func IsFailedOnNotLeaderBytes(err []byte) bool {
if err != nil {
return bytes.HasPrefix(err, FailedOnNotLeaderBytes)
}
return false
}
func IsTopicNotExistBytes(err []byte) bool {
if err != nil {
return bytes.HasPrefix(err, E_TOPIC_NOT_EXIST_BYTES)
}
return false
}
func IsFailedOnNotWritableBytes(err []byte) bool {
if err != nil {
return bytes.HasPrefix(err, FailedOnNotWritableBytes)
}
return false
}
// ErrNotConnected is returned when a publish command is made
// against a Producer that is not connected
var ErrNotConnected = errors.New("not connected")
// ErrStopped is returned when a publish command is
// made against a Producer that has been stopped
var ErrStopped = errors.New("stopped")
// ErrClosing is returned when a connection is closing
var ErrClosing = errors.New("closing")
// ErrAlreadyConnected is returned from ConnectToNSQD when already connected
var ErrAlreadyConnected = errors.New("already connected")
// ErrOverMaxInFlight is returned from Consumer if over max-in-flight
var ErrOverMaxInFlight = errors.New("over configure max-inflight")
// ErrIdentify is returned from Conn as part of the IDENTIFY handshake
type ErrIdentify struct {
Reason string
}
// Error returns a stringified error
func (e ErrIdentify) Error() string {
return fmt.Sprintf("failed to IDENTIFY - %s", e.Reason)
}
// ErrProtocol is returned from Producer when encountering
// an NSQ protocol level error
type ErrProtocol struct {
Reason string
}
// Error returns a stringified error
func (e ErrProtocol) Error() string {
return e.Reason
}