Skip to main content

miden_client/rpc/errors/node/
note.rs

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