Skip to main content

frost_bluepallas/
errors.rs

1//! Error types for the frost-bluepallas library
2
3use alloc::{boxed::Box, string::String};
4use core::{error, fmt, result::Result};
5
6// TODO: Replace with BluePallasError within
7pub type BluePallasResult<T> = Result<T, Box<dyn error::Error>>;
8
9/// Error enum for frost-bluepallas operations
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum BluePallasError {
12    /// Serialization operation failed
13    SerializationError(String),
14
15    /// Deserialization operation failed
16    DeSerializationError(String),
17
18    /// No messages have been provided for signing
19    NoMessageProvided,
20
21    /// Saving Signature failed
22    SaveSignatureError(String),
23
24    /// Invalid Memo provided
25    InvalidMemo(String),
26}
27
28impl fmt::Display for BluePallasError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            BluePallasError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
32            BluePallasError::DeSerializationError(msg) => {
33                write!(f, "Deserialization error: {}", msg)
34            }
35            BluePallasError::NoMessageProvided => {
36                write!(f, "No messages have been provided for signing")
37            }
38            BluePallasError::SaveSignatureError(msg) => {
39                write!(f, "Failed to save signature: {}", msg)
40            }
41            BluePallasError::InvalidMemo(msg) => write!(f, "Invalid memo: {}", msg),
42        }
43    }
44}
45
46impl error::Error for BluePallasError {}
47
48// Convenience constructors
49impl BluePallasError {
50    /// Create a serialization error with a custom message
51    pub fn serialization_error(message: impl Into<String>) -> Self {
52        BluePallasError::SerializationError(message.into())
53    }
54
55    /// Create a deserialization error with a custom message
56    pub fn deserialization_error(message: impl Into<String>) -> Self {
57        BluePallasError::DeSerializationError(message.into())
58    }
59
60    /// Create an invalid memo error with a custom message
61    pub fn invalid_memo(message: impl Into<String>) -> Self {
62        BluePallasError::InvalidMemo(message.into())
63    }
64}