miden_client/rpc/errors/node/sync.rs
1use alloc::string::String;
2
3use thiserror::Error;
4
5// NOTE SYNC ERROR
6// ================================================================================================
7
8// Error codes match `SyncErrorCode` and `SyncNotesErrorCode` in
9// `miden-node/crates/rpc/src/server/api/error_codes.rs`.
10#[derive(Debug, Clone, PartialEq, Eq, Error)]
11pub enum NoteSyncError {
12 /// Internal server error (code 0)
13 #[error("internal server error")]
14 Internal,
15 /// Invalid block range specified
16 #[error("invalid block range")]
17 InvalidBlockRange,
18 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
19 /// the network, so a retry can succeed.
20 #[error("requested block is ahead of the node's chain tip")]
21 FutureBlock,
22 /// Failed to deserialize data
23 #[error("deserialization failed")]
24 DeserializationFailed,
25 /// Error code not recognized by this client version. This can happen if the node is newer than
26 /// the client and has added new error variants.
27 #[error("unknown error code {code}: {message}")]
28 Unknown { code: u8, message: String },
29}
30
31impl NoteSyncError {
32 pub fn from_code(code: u8, message: &str) -> Self {
33 match code {
34 0 => Self::Internal,
35 1 => Self::InvalidBlockRange,
36 2 => Self::FutureBlock,
37 3 => Self::DeserializationFailed,
38 _ => Self::Unknown { code, message: String::from(message) },
39 }
40 }
41}
42
43// SYNC NULLIFIERS ERROR
44// ================================================================================================
45
46// Error codes match `SyncErrorCode` and `SyncNullifiersErrorCode` in
47// `miden-node/crates/rpc/src/server/api/error_codes.rs`.
48#[derive(Debug, Clone, PartialEq, Eq, Error)]
49pub enum SyncNullifiersError {
50 /// Internal server error (code 0)
51 #[error("internal server error")]
52 Internal,
53 /// Invalid block range specified
54 #[error("invalid block range")]
55 InvalidBlockRange,
56 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
57 /// the network, so a retry can succeed.
58 #[error("requested block is ahead of the node's chain tip")]
59 FutureBlock,
60 /// Invalid prefix length
61 #[error("invalid prefix length")]
62 InvalidPrefixLength,
63 /// Failed to deserialize data
64 #[error("deserialization failed")]
65 DeserializationFailed,
66 /// Error code not recognized by this client version. This can happen if the node is newer than
67 /// the client and has added new error variants.
68 #[error("unknown error code {code}: {message}")]
69 Unknown { code: u8, message: String },
70}
71
72impl SyncNullifiersError {
73 pub fn from_code(code: u8, message: &str) -> Self {
74 match code {
75 0 => Self::Internal,
76 1 => Self::InvalidBlockRange,
77 2 => Self::InvalidPrefixLength,
78 3 => Self::DeserializationFailed,
79 4 => Self::FutureBlock,
80 _ => Self::Unknown { code, message: String::from(message) },
81 }
82 }
83}
84
85// SYNC ACCOUNT VAULT ERROR
86// ================================================================================================
87
88// Error codes match `SyncErrorCode` and `SyncAccountVaultErrorCode` in
89// `miden-node/crates/rpc/src/server/api/error_codes.rs`.
90#[derive(Debug, Clone, PartialEq, Eq, Error)]
91pub enum SyncAccountVaultError {
92 /// Internal server error (code 0)
93 #[error("internal server error")]
94 Internal,
95 /// Invalid block range specified
96 #[error("invalid block range")]
97 InvalidBlockRange,
98 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
99 /// the network, so a retry can succeed.
100 #[error("requested block is ahead of the node's chain tip")]
101 FutureBlock,
102 /// Failed to deserialize data
103 #[error("deserialization failed")]
104 DeserializationFailed,
105 /// Account is not public
106 #[error("account is not public")]
107 AccountNotPublic,
108 /// Error code not recognized by this client version. This can happen if the node is newer than
109 /// the client and has added new error variants.
110 #[error("unknown error code {code}: {message}")]
111 Unknown { code: u8, message: String },
112}
113
114impl SyncAccountVaultError {
115 pub fn from_code(code: u8, message: &str) -> Self {
116 match code {
117 0 => Self::Internal,
118 1 => Self::InvalidBlockRange,
119 2 => Self::DeserializationFailed,
120 3 => Self::AccountNotPublic,
121 4 => Self::FutureBlock,
122 _ => Self::Unknown { code, message: String::from(message) },
123 }
124 }
125}
126
127// SYNC ACCOUNT STORAGE MAPS ERROR
128// ================================================================================================
129
130// Error codes match `SyncErrorCode` and `SyncAccountStorageMapsErrorCode` in
131// `miden-node/crates/rpc/src/server/api/error_codes.rs`.
132#[derive(Debug, Clone, PartialEq, Eq, Error)]
133pub enum SyncAccountStorageMapsError {
134 /// Internal server error (code 0)
135 #[error("internal server error")]
136 Internal,
137 /// Invalid block range specified
138 #[error("invalid block range")]
139 InvalidBlockRange,
140 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
141 /// the network, so a retry can succeed.
142 #[error("requested block is ahead of the node's chain tip")]
143 FutureBlock,
144 /// Failed to deserialize data
145 #[error("deserialization failed")]
146 DeserializationFailed,
147 /// Account is not public
148 #[error("account is not public")]
149 AccountNotPublic,
150 /// Error code not recognized by this client version. This can happen if the node is newer than
151 /// the client and has added new error variants.
152 #[error("unknown error code {code}: {message}")]
153 Unknown { code: u8, message: String },
154}
155
156impl SyncAccountStorageMapsError {
157 pub fn from_code(code: u8, message: &str) -> Self {
158 match code {
159 0 => Self::Internal,
160 1 => Self::InvalidBlockRange,
161 2 => Self::DeserializationFailed,
162 4 => Self::AccountNotPublic,
163 5 => Self::FutureBlock,
164 _ => Self::Unknown { code, message: String::from(message) },
165 }
166 }
167}
168
169// SYNC TRANSACTIONS ERROR
170// ================================================================================================
171
172// Error codes match `SyncErrorCode` and `SyncTransactionsErrorCode` in
173// `miden-node/crates/rpc/src/server/api/error_codes.rs`.
174#[derive(Debug, Clone, PartialEq, Eq, Error)]
175pub enum SyncTransactionsError {
176 /// Internal server error (code 0)
177 #[error("internal server error")]
178 Internal,
179 /// Invalid block range specified
180 #[error("invalid block range")]
181 InvalidBlockRange,
182 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
183 /// the network, so a retry can succeed.
184 #[error("requested block is ahead of the node's chain tip")]
185 FutureBlock,
186 /// Failed to deserialize data
187 #[error("deserialization failed")]
188 DeserializationFailed,
189 /// Error code not recognized by this client version. This can happen if the node is newer than
190 /// the client and has added new error variants.
191 #[error("unknown error code {code}: {message}")]
192 Unknown { code: u8, message: String },
193}
194
195impl SyncTransactionsError {
196 pub fn from_code(code: u8, message: &str) -> Self {
197 match code {
198 0 => Self::Internal,
199 1 => Self::InvalidBlockRange,
200 2 => Self::DeserializationFailed,
201 5 => Self::FutureBlock,
202 _ => Self::Unknown { code, message: String::from(message) },
203 }
204 }
205}
206
207// SYNC CHAIN MMR ERROR
208// ================================================================================================
209
210// Error codes match `miden-node/crates/rpc/src/server/api/error_codes.rs::SyncChainMmrErrorCode`.
211#[derive(Debug, Clone, PartialEq, Eq, Error)]
212pub enum SyncChainMmrError {
213 /// Internal server error (code 0)
214 #[error("internal server error")]
215 Internal,
216 /// Requested block is ahead of the node's chain tip. This can happen when the node is behind
217 /// the network, so a retry can succeed.
218 #[error("requested block is ahead of the node's chain tip")]
219 FutureBlock,
220 /// Error code not recognized by this client version. This can happen if the node is newer than
221 /// the client and has added new error variants.
222 #[error("unknown error code {code}: {message}")]
223 Unknown { code: u8, message: String },
224}
225
226impl SyncChainMmrError {
227 pub fn from_code(code: u8, message: &str) -> Self {
228 match code {
229 0 => Self::Internal,
230 2 => Self::FutureBlock,
231 _ => Self::Unknown { code, message: String::from(message) },
232 }
233 }
234}