-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
errors.go
51 lines (40 loc) · 1.03 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 dtx
//A set of errors for the nonblocking DtxDecoder. Should only be used in the debug proxy.
type outofsync interface {
OutOfSync() bool
}
type incomplete interface {
IsIncomplete() bool
}
type dtxError struct {
errormsg string
outOfSync bool
incomplete bool
}
//NewOutOfSync should be used when the MagicBytes are wrong
func NewOutOfSync(message string) error {
return dtxError{message, true, false}
}
//NewIncomplete when the Message was not complete
func NewIncomplete(message string) error {
return dtxError{message, false, true}
}
func (e dtxError) Error() string {
return e.errormsg
}
func (e dtxError) OutOfSync() bool {
return e.outOfSync
}
func (e dtxError) IsIncomplete() bool {
return e.incomplete
}
//IsOutOfSync returns true if err is an OutOfSync error
func IsOutOfSync(err error) bool {
te, ok := err.(outofsync)
return ok && te.OutOfSync()
}
//IsIncomplete returns true if the DtxMessage was incomplete
func IsIncomplete(err error) bool {
te, ok := err.(incomplete)
return ok && te.IsIncomplete()
}