-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
76 lines (61 loc) · 1.88 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
package alternator
import (
"errors"
"fmt"
"log"
"os"
)
var (
// ErrKeyNotFound occurs when a Get was made for an unexisting key
ErrKeyNotFound = errors.New("key not found")
// ErrDataLost occurs when metadata for a name was found, but not its data
ErrDataLost = errors.New("data lost")
// ErrPutMDFail occurs when a node fails to put the metadata in N/2 successors
ErrPutMDFail = errors.New("failed to put metadata in n/2 successors")
// ErrPutFail occurs when a node fails to put the data in required amount of nodes
ErrPutFail = errors.New("failed to replicate in required amount of nodes")
// ErrPutChainDead occurs when the entire chain for a key is down
ErrPutChainDead = errors.New("the key's successor chain is completely down")
// ErrJoinFail occurs when a join request fails
ErrJoinFail = errors.New("join request failed")
// ErrLeaveFail occurs when a leave fails
ErrLeaveFail = errors.New("leave fail")
// ErrBatchPutIncomplete occurs when a batch put fails to put some pairs in the DB
ErrBatchPutIncomplete = errors.New("batch operation did not put all pairs successfully")
// ErrRePutFail occurs when reput fails
ErrRePutFail = errors.New("reput failed")
// ErrNiLCallee occurs when MakeRemoteCall or MakeAsyncCall are called with a nil peer
ErrNilPeer = errors.New("callee is nil")
)
func assertRemoteErr(err error, typ string) bool {
if err == nil {
return false
} else if err.Error() == typ {
// Matched error type
return true
} else {
// Log the incident
log.Print("Unexpected error ", err)
return false
}
}
// Returns true if no error
func checkFatal(msg string, err error) bool {
if err != nil {
// Exits
log.Fatal(msg+": ", err)
}
// No fatal
return false
}
func printExit(msg string) {
fmt.Println(msg)
os.Exit(1)
}
func checkErr(str string, err error) bool {
if err != nil {
log.Print(str+": ", err)
return true
}
return false
}