tendermint/
error.rs

1//! Error types
2
3use alloc::string::String;
4use core::num::TryFromIntError;
5
6use flex_error::{define_error, DisplayOnly};
7use serde::{Deserialize, Serialize};
8
9use crate::account;
10
11define_error! {
12    #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13    Error {
14        Crypto
15            |_| { format_args!("cryptographic error") },
16
17        InvalidKey
18            { detail: String }
19            |e| { format_args!("invalid key: {}", e.detail) },
20
21        Length
22            |_| { format_args!("length error") },
23
24        Parse
25            { data: String }
26            | e | { format_args!("error parsing data: {}", e.data) },
27
28        ParseInt
29            { data: String }
30            [ DisplayOnly<core::num::ParseIntError>]
31            | e | { format_args!("error parsing int data: {}", e.data) },
32
33        Protocol
34            { detail: String }
35            |e| { format_args!("protocol error: {}", e.detail) },
36
37        DateOutOfRange
38            |_| { format_args!("date out of range") },
39
40        DurationOutOfRange
41            |_| { format_args!("duration value out of range") },
42
43        EmptySignature
44            |_| { format_args!("empty signature") },
45
46        SignatureInvalid
47            { detail: String }
48            |e| { format_args!("bad signature: {}", e.detail) },
49
50        InvalidMessageType
51            |_| { format_args!("invalid message type") },
52
53        NegativeHeight
54            [ DisplayOnly<TryFromIntError> ]
55            |_| { format_args!("negative height") },
56
57        NegativeRound
58            [ DisplayOnly<TryFromIntError> ]
59            |_| { format_args!("negative round") },
60
61        NegativePolRound
62            |_| { format_args!("negative POL round") },
63
64        NegativeValidatorIndex
65            [ DisplayOnly<TryFromIntError> ]
66            |_| { format_args!("negative validator index") },
67
68        InvalidHashSize
69            |_| { format_args!("invalid hash: expected hash size to be 32 bytes") },
70
71        NonZeroTimestamp
72            | _ | { "absent commitsig has non-zero timestamp" },
73
74        InvalidAccountIdLength
75            |_| { format_args!("invalid account ID length") },
76
77        InvalidSignatureIdLength
78            |_| { format_args!("invalid signature ID length") },
79
80        IntegerOverflow
81            [ DisplayOnly<TryFromIntError> ]
82            |_| { format_args!("integer overflow") },
83
84        TimestampNanosOutOfRange
85            |_| { format_args!("timestamp nanosecond component is out of range") },
86
87        TimestampConversion
88            |_| { format_args!("timestamp conversion error") },
89
90        NoVoteFound
91            |_| { format_args!("no vote found") },
92
93        NoProposalFound
94            |_| { format_args!("no proposal found") },
95
96        InvalidAppHashLength
97            |_| { format_args!("invalid app hash length") },
98
99        InvalidPartSetHeader
100            { detail : String }
101            |e| { format_args!("invalid part set header: {}", e.detail) },
102
103        MissingHeader
104            |_| { format_args!("missing header field") },
105
106        MissingData
107            |_| { format_args!("missing data field") },
108
109        MissingEvidence
110            |_| { format_args!("missing evidence field") },
111
112        MissingTimestamp
113            |_| { format_args!("missing timestamp field") },
114
115        MissingVersion
116            |_| { format_args!("missing version") },
117
118        MissingMaxAgeDuration
119            |_| { format_args!("missing max_age_duration") },
120
121        MissingPublicKey
122            |_| { format_args!("missing public key") },
123
124        MissingValidator
125            |_| { format_args!("missing validator") },
126
127        MissingLastCommitInfo
128            |_| { format_args!("missing last commit info") },
129
130        MissingGenesisTime
131            |_| { format_args!("missing genesis time") },
132
133        MissingConsensusParams
134            |_| { format_args!("missing consensus params") },
135
136        InvalidTimestamp
137            { reason: String }
138            | e | { format_args!("invalid timestamp: {}", e.reason) },
139
140        InvalidBlock
141            { reason: String }
142            | e | { format_args!("invalid block: {}", e.reason) },
143
144        InvalidFirstHeader
145            |_| { format_args!("last_block_id is not null on first height") },
146
147        InvalidSignature
148            { reason: String }
149            | e | { format_args!("invalid signature: {}", e.reason) },
150
151        InvalidValidatorAddress
152            |_| { format_args!("invalid validator address") },
153
154        InvalidSignedHeader
155            |_| { format_args!("invalid signed header") },
156
157        InvalidEvidence
158            |_| { format_args!("invalid evidence") },
159
160        InvalidValidatorParams
161            |_| { format_args!("invalid validator parameters") },
162
163        InvalidVersionParams
164            |_| { format_args!("invalid version parameters") },
165
166        InvalidAbciRequestType
167            |_| { format_args!("invalid ABCI request type") },
168
169        InvalidAbciResponseType
170            |_| { format_args!("invalid ABCI response type") },
171
172        BlockIdFlag
173            |_| { format_args!("invalid block id flag") },
174
175        NegativePower
176            [ DisplayOnly<TryFromIntError> ]
177            |_| { format_args!("negative power") },
178
179        UnsupportedKeyType
180            |_| { format_args!("unsupported key type" ) },
181
182        UnsupportedCheckTxType
183            |_| { format_args!("unsupported CheckTx type" ) },
184
185        UnsupportedApplySnapshotChunkResult
186            |_| { format_args!("unsupported ApplySnapshotChunkResult type" ) },
187
188        UnsupportedOfferSnapshotChunkResult
189            |_| { format_args!("unsupported OfferSnapshotChunkResult type" ) },
190
191        UnsupportedProcessProposalStatus
192            |_| { format_args!("unsupported ProcessProposal status value" ) },
193
194        UnsupportedVerifyVoteExtensionStatus
195            |_| { format_args!("unsupported VerifyVoteExtension status value" ) },
196
197        NegativeMaxAgeNum
198            [ DisplayOnly<TryFromIntError> ]
199            |_| { format_args!("negative max_age_num_blocks") },
200
201        ProposerNotFound
202            { account: account::Id }
203            |e| { format_args!("proposer with address '{0}' no found in validator set", e.account) },
204
205        TimeParse
206            [ DisplayOnly<time::error::Parse> ]
207            |_| { format_args!("time parsing error") },
208
209        SubtleEncoding
210            [ DisplayOnly<subtle_encoding::Error> ]
211            |_| { format_args!("subtle encoding error") },
212
213        Signature
214            |_| { "signature error" },
215
216        TrustThresholdTooLarge
217            |_| { "trust threshold is too large (must be <= 1)" },
218
219        UndefinedTrustThreshold
220            |_| { "undefined trust threshold (denominator cannot be 0)" },
221
222        TrustThresholdTooSmall
223            |_| { "trust threshold too small (must be >= 1/3)" },
224
225        NegativeProofTotal
226            [ DisplayOnly<TryFromIntError> ]
227            |_| { "negative number of items in proof" },
228
229        NegativeProofIndex
230            [ DisplayOnly<TryFromIntError> ]
231            |_| { "negative item index in proof" },
232
233        TotalVotingPowerMismatch
234            |_| { "total voting power in validator set does not match the sum of participants' powers" },
235
236        TotalVotingPowerOverflow
237            |_| { "total voting power in validator set exceeds the allowed maximum" },
238    }
239}
240
241impl From<core::convert::Infallible> for Error {
242    fn from(_never: core::convert::Infallible) -> Error {
243        unreachable!("Infallible can never be constructed")
244    }
245}