-
Notifications
You must be signed in to change notification settings - Fork 175
/
failures.go
175 lines (139 loc) · 4.4 KB
/
failures.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package errors
import (
"fmt"
)
// UnknownFailure captures an unknown vm fatal error
type UnknownFailure struct {
err error
}
// NewUnknownFailure constructs a new UnknownFailure
func NewUnknownFailure(err error) *UnknownFailure {
return &UnknownFailure{err: err}
}
func (e *UnknownFailure) Error() string {
return fmt.Sprintf("%s unknown failure: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e *UnknownFailure) FailureCode() FailureCode {
return FailureCodeUnknownFailure
}
// Unwrap unwraps the error
func (e UnknownFailure) Unwrap() error {
return e.err
}
// EncodingFailure captures an fatal error sourced from encoding issues
type EncodingFailure struct {
err error
}
// NewEncodingFailuref formats and returns a new EncodingFailure
func NewEncodingFailuref(msg string, err error) *EncodingFailure {
return &EncodingFailure{
err: fmt.Errorf(msg, err),
}
}
func (e *EncodingFailure) Error() string {
return fmt.Sprintf("%s encoding failed: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e *EncodingFailure) FailureCode() FailureCode {
return FailureCodeEncodingFailure
}
// Unwrap unwraps the error
func (e EncodingFailure) Unwrap() error {
return e.err
}
// LedgerFailure captures a fatal error cause by ledger failures
type LedgerFailure struct {
err error
}
// NewLedgerFailure constructs a new LedgerFailure
func NewLedgerFailure(err error) *LedgerFailure {
return &LedgerFailure{err: err}
}
func (e *LedgerFailure) Error() string {
return fmt.Sprintf("%s ledger returns unsuccessful: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e *LedgerFailure) FailureCode() FailureCode {
return FailureCodeLedgerFailure
}
// Unwrap unwraps the error
func (e LedgerFailure) Unwrap() error {
return e.err
}
// StateMergeFailure captures a fatal caused by state merge
type StateMergeFailure struct {
err error
}
// NewStateMergeFailure constructs a new StateMergeFailure
func NewStateMergeFailure(err error) *StateMergeFailure {
return &StateMergeFailure{err: err}
}
func (e StateMergeFailure) Error() string {
return fmt.Sprintf("%s can not merge the state: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e StateMergeFailure) FailureCode() FailureCode {
return FailureCodeStateMergeFailure
}
// Unwrap unwraps the error
func (e StateMergeFailure) Unwrap() error {
return e.err
}
// BlockFinderFailure captures a fatal caused by block finder
type BlockFinderFailure struct {
err error
}
// NewBlockFinderFailure constructs a new BlockFinderFailure
func NewBlockFinderFailure(err error) *BlockFinderFailure {
return &BlockFinderFailure{err: err}
}
func (e BlockFinderFailure) Error() string {
return fmt.Sprintf("%s can not retrieve the block: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e BlockFinderFailure) FailureCode() FailureCode {
return FailureCodeBlockFinderFailure
}
// Unwrap unwraps the error
func (e BlockFinderFailure) Unwrap() error {
return e.err
}
// HasherFailure captures a fatal caused by hasher
type HasherFailure struct {
err error
}
// NewHasherFailuref constructs a new hasherFailure
func NewHasherFailuref(msg string, args ...interface{}) *HasherFailure {
return &HasherFailure{err: fmt.Errorf(msg, args...)}
}
func (e HasherFailure) Error() string {
return fmt.Sprintf("%s hasher failed: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e HasherFailure) FailureCode() FailureCode {
return FailureCodeHasherFailure
}
// Unwrap unwraps the error
func (e HasherFailure) Unwrap() error {
return e.err
}
// MetaTransactionFailure captures a fatal caused by invoking a meta transaction
type MetaTransactionFailure struct {
err error
}
// NewMetaTransactionFailuref constructs a new hasherFailure
func NewMetaTransactionFailuref(msg string, args ...interface{}) *MetaTransactionFailure {
return &MetaTransactionFailure{err: fmt.Errorf(msg, args...)}
}
func (e MetaTransactionFailure) Error() string {
return fmt.Sprintf("%s meta transaction failed: %s", e.FailureCode().String(), e.err.Error())
}
// FailureCode returns the failure code
func (e MetaTransactionFailure) FailureCode() FailureCode {
return FailureCodeMetaTransactionFailure
}
// Unwrap unwraps the error
func (e MetaTransactionFailure) Unwrap() error {
return e.err
}