-
Notifications
You must be signed in to change notification settings - Fork 14
/
errors.go
52 lines (45 loc) · 1.21 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
package gorums
import (
"errors"
"fmt"
"strings"
)
// Incomplete is the error returned by a quorum call when the call cannot completed
// due insufficient non-error replies to form a quorum according to the quorum function.
var Incomplete = errors.New("incomplete call")
// QuorumCallError reports on a failed quorum call.
type QuorumCallError struct {
cause error
errors []nodeError
replies int
}
// Is reports whether the target error is the same as the cause of the QuorumCallError.
func (e QuorumCallError) Is(target error) bool {
if t, ok := target.(QuorumCallError); ok {
return e.cause == t.cause
}
return e.cause == target
}
func (e QuorumCallError) Error() string {
s := fmt.Sprintf("quorum call error: %s (errors: %d, replies: %d)", e.cause, len(e.errors), e.replies)
var b strings.Builder
b.WriteString(s)
if len(e.errors) == 0 {
return b.String()
}
b.WriteString("\nnode errors:\n")
for _, err := range e.errors {
b.WriteByte('\t')
b.WriteString(err.Error())
b.WriteByte('\n')
}
return b.String()
}
// nodeError reports on a failed RPC call.
type nodeError struct {
cause error
nodeID uint32
}
func (e nodeError) Error() string {
return fmt.Sprintf("node %d: %v", e.nodeID, e.cause)
}