Skip to main content

miden_client/rpc/errors/node/
block.rs

1use alloc::string::String;
2
3use thiserror::Error;
4
5// GET BLOCK HEADER ERROR
6// ================================================================================================
7
8// Error codes match `miden-node/crates/store/src/errors.rs::GetBlockHeaderError`.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum GetBlockHeaderError {
11    /// Internal server error (code 0)
12    #[error("internal server error")]
13    Internal,
14    /// Error code not recognized by this client version. This can happen if the node
15    /// is newer than the client and has added new error variants.
16    #[error("unknown error code {code}: {message}")]
17    Unknown { code: u8, message: String },
18}
19
20impl GetBlockHeaderError {
21    pub fn from_code(code: u8, message: &str) -> Self {
22        match code {
23            0 => Self::Internal,
24            _ => Self::Unknown { code, message: String::from(message) },
25        }
26    }
27}
28
29// GET BLOCK BY NUMBER ERROR
30// ================================================================================================
31
32// Error codes match `miden-node/crates/store/src/errors.rs::GetBlockByNumberError`.
33#[derive(Debug, Clone, PartialEq, Eq, Error)]
34pub enum GetBlockByNumberError {
35    /// Internal server error (code 0)
36    #[error("internal server error")]
37    Internal,
38    /// Failed to deserialize data
39    #[error("deserialization failed")]
40    DeserializationFailed,
41    /// Error code not recognized by this client version. This can happen if the node
42    /// is newer than the client and has added new error variants.
43    #[error("unknown error code {code}: {message}")]
44    Unknown { code: u8, message: String },
45}
46
47impl GetBlockByNumberError {
48    pub fn from_code(code: u8, message: &str) -> Self {
49        match code {
50            0 => Self::Internal,
51            1 => Self::DeserializationFailed,
52            _ => Self::Unknown { code, message: String::from(message) },
53        }
54    }
55}