Skip to main content

octra_sqlite/protocol/
error.rs

1//! Errors raised by transport-independent protocol codecs.
2
3use std::fmt;
4
5/// Result alias for protocol encoding and decoding.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Error returned by transport-independent protocol code.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct Error {
11    message: String,
12}
13
14impl Error {
15    /// Construct a protocol error with human-readable context.
16    pub fn new(message: impl Into<String>) -> Self {
17        Self {
18            message: message.into(),
19        }
20    }
21}
22
23impl fmt::Display for Error {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        f.write_str(&self.message)
26    }
27}
28
29impl std::error::Error for Error {}
30
31impl From<base64::DecodeError> for Error {
32    fn from(error: base64::DecodeError) -> Self {
33        Self::new(error.to_string())
34    }
35}