/
error.go
58 lines (51 loc) · 1.6 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
package blsbft
import (
"fmt"
"github.com/pkg/errors"
)
const (
UnExpectedError = iota
ConsensusTypeNotExistError
ProducerSignatureError
CommitteeSignatureError
CombineSignatureError
SignDataError
LoadKeyError
ConsensusAlreadyStartedError
ConsensusAlreadyStoppedError
DecodeValidationDataError
EncodeValidationDataError
BlockCreationError
)
var ErrCodeMessage = map[int]struct {
Code int
message string
}{
UnExpectedError: {-1000, "Unexpected error"},
ConsensusTypeNotExistError: {-1001, "Consensus type isn't exist"},
ProducerSignatureError: {-1002, "Producer signature error"},
CommitteeSignatureError: {-1003, "Committee signature error"},
CombineSignatureError: {-1004, "Combine signature error"},
SignDataError: {-1005, "Sign data error"},
LoadKeyError: {-1006, "Load key error"},
ConsensusAlreadyStartedError: {-1007, "consensus already started error"},
ConsensusAlreadyStoppedError: {-1008, "consensus already stopped error"},
DecodeValidationDataError: {-1009, "Decode Validation Data error"},
EncodeValidationDataError: {-1010, "Encode Validation Data Error"},
BlockCreationError: {-1011, "Block Creation Error"},
}
type ConsensusError struct {
Code int
Message string
err error
}
func (e ConsensusError) Error() string {
return fmt.Sprintf("%d: %s \n %+v", e.Code, e.Message, e.err)
}
func NewConsensusError(key int, err error) error {
return &ConsensusError{
Code: ErrCodeMessage[key].Code,
Message: ErrCodeMessage[key].message,
err: errors.Wrap(err, ErrCodeMessage[key].message),
}
}