-
Notifications
You must be signed in to change notification settings - Fork 175
/
base.go
233 lines (192 loc) · 6.25 KB
/
base.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package errors
import (
"fmt"
"github.com/onflow/cadence/runtime"
"github.com/onflow/flow-go/model/flow"
)
// InvalidAddressError indicates that a transaction references an invalid flow Address
// in either the Authorizers or Payer field.
type InvalidAddressError struct {
address flow.Address
err error
}
// Address returns the invalid address
func (e InvalidAddressError) Address() flow.Address {
return e.address
}
// NewInvalidAddressErrorf constructs a new InvalidAddressError
func NewInvalidAddressErrorf(address flow.Address, msg string, args ...interface{}) *InvalidAddressError {
return &InvalidAddressError{address: address, err: fmt.Errorf(msg, args...)}
}
func (e InvalidAddressError) Error() string {
return fmt.Sprintf("%s invalid address (%s): %s", e.Code().String(), e.address.String(), e.err.Error())
}
// Code returns the error code for this error type
func (e InvalidAddressError) Code() ErrorCode {
return ErrCodeInvalidAddressError
}
// Unwrap unwraps the error
func (e InvalidAddressError) Unwrap() error {
return e.err
}
// InvalidArgumentError indicates that a transaction includes invalid arguments.
// this error is the result of failure in any of the following conditions:
// - number of arguments doesn't match the template
// TODO add more cases like argument size
type InvalidArgumentError struct {
err error
}
// NewInvalidArgumentErrorf constructs a new InvalidArgumentError
func NewInvalidArgumentErrorf(msg string, args ...interface{}) *InvalidArgumentError {
return &InvalidArgumentError{err: fmt.Errorf(msg, args...)}
}
func (e InvalidArgumentError) Error() string {
return fmt.Sprintf("%s transaction arguments are invalid: (%s)", e.Code().String(), e.err.Error())
}
// Code returns the error code for this error type
func (e InvalidArgumentError) Code() ErrorCode {
return ErrCodeInvalidArgumentError
}
// Unwrap unwraps the error
func (e InvalidArgumentError) Unwrap() error {
return e.err
}
// InvalidLocationError indicates an invalid location is passed
type InvalidLocationError struct {
location runtime.Location
err error
}
// NewInvalidLocationErrorf constructs a new InvalidLocationError
func NewInvalidLocationErrorf(location runtime.Location, msg string, args ...interface{}) *InvalidLocationError {
return &InvalidLocationError{location: location, err: fmt.Errorf(msg, args...)}
}
func (e InvalidLocationError) Error() string {
errMsg := ""
if e.err != nil {
errMsg = e.err.Error()
}
locationStr := ""
if e.location != nil {
locationStr = e.location.String()
}
return fmt.Sprintf(
"%s location (%s) is not a valid location: %s",
e.Code().String(),
locationStr,
errMsg,
)
}
// Code returns the error code for this error
func (e InvalidLocationError) Code() ErrorCode {
return ErrCodeInvalidLocationError
}
// Unwrap unwraps the error
func (e InvalidLocationError) Unwrap() error {
return e.err
}
// ValueError indicates a value is not valid value.
type ValueError struct {
valueStr string
err error
}
// NewValueErrorf constructs a new ValueError
func NewValueErrorf(valueStr string, msg string, args ...interface{}) *ValueError {
return &ValueError{valueStr: valueStr, err: fmt.Errorf(msg, args...)}
}
func (e ValueError) Error() string {
errMsg := ""
if e.err != nil {
errMsg = e.err.Error()
}
return fmt.Sprintf("%s invalid value (%s): %s", e.Code().String(), e.valueStr, errMsg)
}
// Code returns the error code for this error type
func (e ValueError) Code() ErrorCode {
return ErrCodeValueError
}
// Unwrap unwraps the error
func (e ValueError) Unwrap() error {
return e.err
}
// OperationAuthorizationError indicates not enough authorization
// to performe an operations like account creation or smart contract deployment.
type OperationAuthorizationError struct {
operation string
err error
}
// NewOperationAuthorizationErrorf constructs a new OperationAuthorizationError
func NewOperationAuthorizationErrorf(operation string, msg string, args ...interface{}) *OperationAuthorizationError {
return &OperationAuthorizationError{operation: operation, err: fmt.Errorf(msg, args...)}
}
func (e OperationAuthorizationError) Error() string {
errMsg := ""
if e.err != nil {
errMsg = e.err.Error()
}
return fmt.Sprintf(
"%s (%s) is not authorized: %s",
e.Code().String(),
e.operation,
errMsg,
)
}
// Code returns the error code for this error type
func (e OperationAuthorizationError) Code() ErrorCode {
return ErrCodeAccountAuthorizationError
}
// Unwrap unwraps the error
func (e OperationAuthorizationError) Unwrap() error {
return e.err
}
// AccountAuthorizationError indicates that an authorization issues
// either a transaction is missing a required signature to
// authorize access to an account or a transaction doesn't have authorization
// to performe some operations like account creation.
type AccountAuthorizationError struct {
address flow.Address
err error
}
// NewAccountAuthorizationErrorf constructs a new AccountAuthorizationError
func NewAccountAuthorizationErrorf(address flow.Address, msg string, args ...interface{}) *AccountAuthorizationError {
return &AccountAuthorizationError{address: address, err: fmt.Errorf(msg, args...)}
}
// Address returns the address of an account without enough authorization
func (e AccountAuthorizationError) Address() flow.Address {
return e.address
}
func (e AccountAuthorizationError) Error() string {
errMsg := ""
if e.err != nil {
errMsg = e.err.Error()
}
return fmt.Sprintf(
"%s authorization failed for account %s: %s",
e.Code().String(),
e.address,
errMsg,
)
}
// Code returns the error code for this error type
func (e AccountAuthorizationError) Code() ErrorCode {
return ErrCodeAccountAuthorizationError
}
// Unwrap unwraps the error
func (e AccountAuthorizationError) Unwrap() error {
return e.err
}
// FVMInternalError indicates that an internal error occurs during tx execution.
type FVMInternalError struct {
msg string
err error
}
// NewFVMInternalErrorf constructs a new FVMInternalError
func NewFVMInternalErrorf(msg string, args ...interface{}) *FVMInternalError {
return &FVMInternalError{err: fmt.Errorf(msg, args...)}
}
func (e *FVMInternalError) Error() string {
return e.msg
}
// Code returns the error code for this error type
func (e *FVMInternalError) Code() ErrorCode {
return ErrCodeFVMInternalError
}