-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
176 lines (139 loc) · 5.73 KB
/
errors.go
File metadata and controls
176 lines (139 loc) · 5.73 KB
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
package mcms
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/mcms/types"
)
// OperationNotReadyError is returned when an operation is not yet ready.
type OperationNotReadyError struct {
OpIndex int
}
// Error implements the error interface.
func (e OperationNotReadyError) Error() string {
return fmt.Sprintf("operation %d is not ready", e.OpIndex)
}
// OperationNotPendingError is returned when an operation is not yet pending.
type OperationNotPendingError struct {
OpIndex int
}
// Error implements the error interface.
func (e OperationNotPendingError) Error() string {
return fmt.Sprintf("operation %d is not pending", e.OpIndex)
}
// OperationNotDoneError is returned when an operation is not yet done.
type OperationNotDoneError struct {
OpIndex int
}
// Error implements the error interface.
func (e OperationNotDoneError) Error() string {
return fmt.Sprintf("operation %d is not done", e.OpIndex)
}
// InvalidProposalKindError is returned when an invalid proposal kind is provided.
type InvalidProposalKindError struct {
ProvidedKind types.ProposalKind
AcceptedKind types.ProposalKind
}
func (e *InvalidProposalKindError) Error() string {
return fmt.Sprintf("invalid proposal kind: %s, value accepted is %s", e.ProvidedKind, e.AcceptedKind)
}
func NewInvalidProposalKindError(provided, accepted types.ProposalKind) *InvalidProposalKindError {
return &InvalidProposalKindError{ProvidedKind: provided, AcceptedKind: accepted}
}
// EncoderNotFoundError is returned when an encoder is not found for a chain in a proposal.
type EncoderNotFoundError struct {
ChainSelector types.ChainSelector
}
// NewEncoderNotFoundError creates a new EncoderNotFoundError.
func NewEncoderNotFoundError(sel types.ChainSelector) *EncoderNotFoundError {
return &EncoderNotFoundError{ChainSelector: sel}
}
func (e *EncoderNotFoundError) Error() string {
return fmt.Sprintf("encoder not provided for chain selector %d", e.ChainSelector)
}
// ChainMetadataNotFoundError is returned when the chain metadata for a chain is not found in a
// proposal.
type ChainMetadataNotFoundError struct {
ChainSelector types.ChainSelector
}
// NewChainMetadataNotFoundError creates a new ChainMetadataNotFoundError.
func NewChainMetadataNotFoundError(sel types.ChainSelector) *ChainMetadataNotFoundError {
return &ChainMetadataNotFoundError{ChainSelector: sel}
}
func (e *ChainMetadataNotFoundError) Error() string {
return fmt.Sprintf("missing metadata for chain %d", e.ChainSelector)
}
// InconsistentConfigsError is returned when the configs for two chains are not equal to each
// other.
type InconsistentConfigsError struct {
ChainSelectorA types.ChainSelector
ChainSelectorB types.ChainSelector
}
// NewInconsistentConfigsError creates a new InconsistentConfigsError.
func NewInconsistentConfigsError(selA, selB types.ChainSelector) *InconsistentConfigsError {
return &InconsistentConfigsError{ChainSelectorA: selA, ChainSelectorB: selB}
}
func (e *InconsistentConfigsError) Error() string {
return fmt.Sprintf("inconsistent configs for chains %d and %d", e.ChainSelectorA, e.ChainSelectorB)
}
// QuorumNotReachedError is returned when the quorum has not been reach as defined in a chain's
// MCM contract configuration.
type QuorumNotReachedError struct {
ChainSelector types.ChainSelector
}
// NewQuorumNotReachedError creates a new QuorumNotReachedError.
func NewQuorumNotReachedError(sel types.ChainSelector) *QuorumNotReachedError {
return &QuorumNotReachedError{ChainSelector: sel}
}
func (e QuorumNotReachedError) Error() string {
return fmt.Sprintf("quorum not reached for chain %d", e.ChainSelector)
}
type InvalidValidUntilError struct {
ReceivedValidUntil uint32
}
func (e *InvalidValidUntilError) Error() string {
return fmt.Sprintf("invalid valid until: %v", e.ReceivedValidUntil)
}
func NewInvalidValidUntilError(receivedValidUntil uint32) *InvalidValidUntilError {
return &InvalidValidUntilError{ReceivedValidUntil: receivedValidUntil}
}
var ErrNoTransactionsInBatch = errors.New("no transactions in batch")
type InvalidSignatureError struct {
RecoveredAddress common.Address
}
func (e *InvalidSignatureError) Error() string {
return fmt.Sprintf("invalid signature: received signature for address %s is not a valid signer in the MCMS proposal", e.RecoveredAddress)
}
func NewInvalidSignatureError(recoveredAddress common.Address) *InvalidSignatureError {
return &InvalidSignatureError{RecoveredAddress: recoveredAddress}
}
// InvalidSignatureAtIndexError provides detailed information about which signature is invalid
type InvalidSignatureAtIndexError struct {
Index int
Signature types.Signature
RecoveredAddress common.Address
RecoveryError error
}
func (e *InvalidSignatureAtIndexError) Error() string {
if e.RecoveryError != nil {
return fmt.Sprintf("signature at index %d is invalid: failed to recover address from signature (r=%s, s=%s, v=%d): %v",
e.Index, e.Signature.R.Hex(), e.Signature.S.Hex(), e.Signature.V, e.RecoveryError)
}
return fmt.Sprintf("signature at index %d is invalid: recovered address %s is not a valid signer (signature: r=%s, s=%s, v=%d)",
e.Index, e.RecoveredAddress.Hex(), e.Signature.R.Hex(), e.Signature.S.Hex(), e.Signature.V)
}
func NewInvalidSignatureAtIndexError(index int, sig types.Signature, recoveredAddr common.Address, recoveryErr error) *InvalidSignatureAtIndexError {
return &InvalidSignatureAtIndexError{
Index: index,
Signature: sig,
RecoveredAddress: recoveredAddr,
RecoveryError: recoveryErr,
}
}
// DuplicateSignersError is returned when proposal signatures contain the same signer more than once.
type DuplicateSignersError struct {
signer string
}
func (e *DuplicateSignersError) Error() string {
return "duplicate signer detected: " + e.signer
}