puffin/algebra/
error.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6pub enum FnError {
7    Unknown(String),
8    /// Error which happened because a cryptographic operation failed.
9    Crypto(String),
10    /// Error which happens because the term is malformed (e.g. a field is missing)
11    Malformed(String),
12    /// Error which happens because of Codec needs to be used and failed (most likely read failed)
13    Codec(String),
14}
15
16impl std::error::Error for FnError {}
17
18impl From<String> for FnError {
19    fn from(message: String) -> Self {
20        Self::Unknown(message)
21    }
22}
23
24impl fmt::Display for FnError {
25    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26        match self {
27            Self::Unknown(msg) => write!(f, "[!!UNKNOWN!!] error in fn: {msg}"),
28            Self::Crypto(msg) => write!(f, "[Crypto] error in fn from rustls: {msg}"),
29            Self::Malformed(msg) => write!(f, "[Malformed] error in fn from rustls: {msg}"),
30            Self::Codec(msg) => write!(
31                f,
32                "[Codec] error in fn from rustls due to a Codec usage: {msg}"
33            ),
34        }
35    }
36}