forked from CosmWasm/wasmd
/
errors.go
150 lines (112 loc) · 5.97 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
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
package types
import (
errorsmod "cosmossdk.io/errors"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
)
// Codes for wasm contract errors
var (
DefaultCodespace = ModuleName
// Note: never use code 1 for any errors - that is reserved for ErrInternal in the core cosmos sdk
// ErrCreateFailed error for wasm code that has already been uploaded or failed
ErrCreateFailed = errorsmod.Register(DefaultCodespace, 2, "create wasm contract failed")
// ErrAccountExists error for a contract account that already exists
ErrAccountExists = errorsmod.Register(DefaultCodespace, 3, "contract account already exists")
// ErrInstantiateFailed error for rust instantiate contract failure
ErrInstantiateFailed = errorsmod.Register(DefaultCodespace, 4, "instantiate wasm contract failed")
// ErrExecuteFailed error for rust execution contract failure
ErrExecuteFailed = errorsmod.Register(DefaultCodespace, 5, "execute wasm contract failed")
// ErrGasLimit error for out of gas
ErrGasLimit = errorsmod.Register(DefaultCodespace, 6, "insufficient gas")
// ErrInvalidGenesis error for invalid genesis file syntax
ErrInvalidGenesis = errorsmod.Register(DefaultCodespace, 7, "invalid genesis")
// ErrNotFound error for an entry not found in the store
ErrNotFound = errorsmod.Register(DefaultCodespace, 8, "not found")
// ErrQueryFailed error for rust smart query contract failure
ErrQueryFailed = errorsmod.Register(DefaultCodespace, 9, "query wasm contract failed")
// ErrInvalidMsg error when we cannot process the error returned from the contract
ErrInvalidMsg = errorsmod.Register(DefaultCodespace, 10, "invalid CosmosMsg from the contract")
// ErrMigrationFailed error for rust execution contract failure
ErrMigrationFailed = errorsmod.Register(DefaultCodespace, 11, "migrate wasm contract failed")
// ErrEmpty error for empty content
ErrEmpty = errorsmod.Register(DefaultCodespace, 12, "empty")
// ErrLimit error for content that exceeds a limit
ErrLimit = errorsmod.Register(DefaultCodespace, 13, "exceeds limit")
// ErrInvalid error for content that is invalid in this context
ErrInvalid = errorsmod.Register(DefaultCodespace, 14, "invalid")
// ErrDuplicate error for content that exists
ErrDuplicate = errorsmod.Register(DefaultCodespace, 15, "duplicate")
// ErrMaxIBCChannels error for maximum number of ibc channels reached
ErrMaxIBCChannels = errorsmod.Register(DefaultCodespace, 16, "max transfer channels")
// ErrUnsupportedForContract error when a capability is used that is not supported for/ by this contract
ErrUnsupportedForContract = errorsmod.Register(DefaultCodespace, 17, "unsupported for this contract")
// ErrPinContractFailed error for pinning contract failures
ErrPinContractFailed = errorsmod.Register(DefaultCodespace, 18, "pinning contract failed")
// ErrUnpinContractFailed error for unpinning contract failures
ErrUnpinContractFailed = errorsmod.Register(DefaultCodespace, 19, "unpinning contract failed")
// ErrUnknownMsg error by a message handler to show that it is not responsible for this message type
ErrUnknownMsg = errorsmod.Register(DefaultCodespace, 20, "unknown message from the contract")
// ErrInvalidEvent error if an attribute/event from the contract is invalid
ErrInvalidEvent = errorsmod.Register(DefaultCodespace, 21, "invalid event")
// ErrNoSuchContractFn error factory for an error when an address does not belong to a contract
ErrNoSuchContractFn = WasmVMFlavouredErrorFactory(errorsmod.Register(DefaultCodespace, 22, "no such contract"),
func(addr string) error { return wasmvmtypes.NoSuchContract{Addr: addr} },
)
// code 23 -26 were used for json parser
// ErrExceedMaxQueryStackSize error if max query stack size is exceeded
ErrExceedMaxQueryStackSize = errorsmod.Register(DefaultCodespace, 27, "max query stack size exceeded")
// ErrNoSuchCodeFn factory for an error when a code id does not belong to a code info
ErrNoSuchCodeFn = WasmVMFlavouredErrorFactory(errorsmod.Register(DefaultCodespace, 28, "no such code"),
func(id uint64) error { return wasmvmtypes.NoSuchCode{CodeID: id} },
)
)
// WasmVMErrorable mapped error type in wasmvm and are not redacted
type WasmVMErrorable interface {
// ToWasmVMError convert instance to wasmvm friendly error if possible otherwise root cause. never nil
ToWasmVMError() error
}
var _ WasmVMErrorable = WasmVMFlavouredError{}
// WasmVMFlavouredError wrapper for sdk error that supports wasmvm error types
type WasmVMFlavouredError struct {
sdkErr *errorsmod.Error
wasmVMErr error
}
// NewWasmVMFlavouredError constructor
func NewWasmVMFlavouredError(sdkErr *errorsmod.Error, wasmVMErr error) WasmVMFlavouredError {
return WasmVMFlavouredError{sdkErr: sdkErr, wasmVMErr: wasmVMErr}
}
// WasmVMFlavouredErrorFactory is a factory method to build a WasmVMFlavouredError type
func WasmVMFlavouredErrorFactory[T any](sdkErr *errorsmod.Error, wasmVMErrBuilder func(T) error) func(T) WasmVMFlavouredError {
if wasmVMErrBuilder == nil {
panic("builder function required")
}
return func(d T) WasmVMFlavouredError {
return WasmVMFlavouredError{sdkErr: sdkErr, wasmVMErr: wasmVMErrBuilder(d)}
}
}
// ToWasmVMError implements WasmVMError-able
func (e WasmVMFlavouredError) ToWasmVMError() error {
if e.wasmVMErr != nil {
return e.wasmVMErr
}
return e.sdkErr
}
// implements stdlib error
func (e WasmVMFlavouredError) Error() string {
return e.sdkErr.Error()
}
// Unwrap implements the built-in errors.Unwrap
func (e WasmVMFlavouredError) Unwrap() error {
return e.sdkErr
}
// Cause is the same as unwrap but used by errors.abci
func (e WasmVMFlavouredError) Cause() error {
return e.Unwrap()
}
// Wrap extends this error with additional information.
// It's a handy function to call Wrap with sdk errors.
func (e WasmVMFlavouredError) Wrap(desc string) error { return errorsmod.Wrap(e, desc) }
// Wrapf extends this error with additional information.
// It's a handy function to call Wrapf with sdk errors.
func (e WasmVMFlavouredError) Wrapf(desc string, args ...interface{}) error {
return errorsmod.Wrapf(e, desc, args...)
}