forked from solana-labs/solana-ping-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
144 lines (125 loc) · 5.11 KB
/
error.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"errors"
"strings"
)
// ping response error type
type PingResultError string
const EmptyPingResultError = ""
// self defined Errors
var (
ErrInvalidCluster = errors.New("invalid cluster")
ErrFindIndexNotFound = errors.New("findIndex does not find pattern")
ErrParseMessageError = errors.New("parse message error")
ErrConvertWrongType = errors.New("parse result convert to type fail")
ErrParseSplit = errors.New("split message fail")
ErrResultInvalid = errors.New("invalid Result")
ErrNoPingResult = errors.New("no Ping Result")
ErrNoPingResultRecord = errors.New("no Ping Result Record")
ErrNoPingResultShort = errors.New("PingResultError has no shortname")
ErrTransactionLoss = errors.New("TransactionLoss")
ErrInProcessedStateTimeout = errors.New("TxHash is still in processd state but timeout")
ErrWaitForConfirmedTimeout = errors.New("Wait for a confirmed block timeout")
ErrGetKeyPair = errors.New("No valid KeyPair")
ErrKeyPairFile = errors.New("Read KeyPair File Error")
)
// Setup Statistic / Alert / Report Error Exception List
var (
ResponseErrIdentifierList []ErrRespIdentifier
// Error which does not use in Statistic computation
StatisticErrorExceptionList []ErrRespIdentifier
// Error does not show in slack alert
AlertErrorExceptionList []ErrRespIdentifier
// Error does not show in the report Error List
ReportErrorExceptionList []ErrRespIdentifier
// error that does not be added into TakeTime
PingTakeTimeErrExpectionList []ErrRespIdentifier
)
func (e PingResultError) IsBlockhashNotFound() bool {
return BlockhashNotFound.IsIdentical(e)
}
func (e PingResultError) IsTransactionHasAlreadyBeenProcessed() bool {
return TransactionHasAlreadyBeenProcessed.IsIdentical(e)
}
func (e PingResultError) IsRPCServerDeadlineExceeded() bool {
return RPCServerDeadlineExceeded.IsIdentical(e)
}
func (e PingResultError) IsServiceUnavilable() bool {
return ServiceUnavilable503.IsIdentical(e)
}
func (e PingResultError) IsTooManyRequest429() bool {
return TooManyRequest429.IsIdentical(e)
}
func (e PingResultError) IsNumSlotsBehind() bool {
return NumSlotsBehind.IsIdentical(e)
}
func (e PingResultError) IsErrRPCEOF() bool {
return RPCEOF.IsIdentical(e)
}
func (e PingResultError) IsErrGatewayTimeout504() bool {
return GatewayTimeout504.IsIdentical(e)
}
func (e PingResultError) IsConnectionRefused() bool {
return ConnectionRefused.IsIdentical(e)
}
func (e PingResultError) IsNoSuchHost() bool {
return NoSuchHost.IsIdentical(e)
}
func (p PingResultError) IsInErrorList(inErrs []ErrRespIdentifier) bool {
for _, idf := range inErrs {
if idf.IsIdentical(p) {
return true
}
}
return false
}
func (p PingResultError) Short() string {
for _, idf := range ResponseErrIdentifierList {
if idf.IsIdentical(p) {
return idf.Short
}
}
return string(p)
}
func (p PingResultError) Subsitute(old string, new string) string {
return strings.ReplaceAll(string(p), old, new)
}
func (p PingResultError) HasError() bool {
return p != EmptyPingResultError
}
func ResponseErrIdentifierInit() []ErrRespIdentifier {
ResponseErrIdentifierList = []ErrRespIdentifier{}
ResponseErrIdentifierList = append(ResponseErrIdentifierList, BlockhashNotFound)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, TransactionHasAlreadyBeenProcessed)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, RPCServerDeadlineExceeded)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, ServiceUnavilable503)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, TooManyRequest429)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, NumSlotsBehind)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, RPCEOF)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, GatewayTimeout504)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, NoSuchHost)
ResponseErrIdentifierList = append(ResponseErrIdentifierList, TxHasAlreadyProcess)
return ResponseErrIdentifierList
}
func StatisticErrExpectionInit() []ErrRespIdentifier {
StatisticErrorExceptionList = []ErrRespIdentifier{}
StatisticErrorExceptionList = append(StatisticErrorExceptionList, BlockhashNotFound)
StatisticErrorExceptionList = append(StatisticErrorExceptionList, TransactionHasAlreadyBeenProcessed)
return StatisticErrorExceptionList
}
func AlertErrExpectionInit() []ErrRespIdentifier {
AlertErrorExceptionList = []ErrRespIdentifier{}
AlertErrorExceptionList = append(AlertErrorExceptionList, RPCServerDeadlineExceeded)
AlertErrorExceptionList = append(AlertErrorExceptionList, BlockhashNotFound)
AlertErrorExceptionList = append(AlertErrorExceptionList, TransactionHasAlreadyBeenProcessed)
return AlertErrorExceptionList
}
func ReportErrExpectionInit() []ErrRespIdentifier {
ReportErrorExceptionList = []ErrRespIdentifier{}
ReportErrorExceptionList = append(ReportErrorExceptionList, TransactionHasAlreadyBeenProcessed)
return ReportErrorExceptionList
}
func PingTakeTimeErrExpectionInit() []ErrRespIdentifier {
PingTakeTimeErrExpectionList = []ErrRespIdentifier{}
return PingTakeTimeErrExpectionList
}