use std::{fmt, io};
use crate::algebra::error::FnError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Fn(FnError),
Term(String),
Codec(String),
Put(String),
IO(String),
Agent(String),
Stream(String),
Extraction(),
SecurityClaim(&'static str),
}
impl std::error::Error for Error {}
impl From<anyhow::Error> for Error {
fn from(value: anyhow::Error) -> Self {
Self::Term(format!("AnyHow Error: {value}"))
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Fn(err) => write!(f, "error executing a function symbol: {err}"),
Self::Term(err) => write!(f, "error evaluating a term: {err}"),
Error::Codec(err) => write!(
f,
"error encoding/reading an EvaluatedTerm/bitstring: {err}"
),
Self::Put(err) => write!(f, "error in openssl: {err}"),
Self::IO(err) => write!(f, "error in io of openssl (this should not happen): {err}"),
Self::Agent(err) => write!(f, "error regarding an agent: {err}"),
Self::Stream(err) => write!(f, "error in the stream: {err}"),
Self::Extraction() => write!(f, "error while extracting variable",),
Self::SecurityClaim(msg) => {
write!(f, "error because a security violation occurred. msg: {msg}")
}
}
}
}
impl From<FnError> for Error {
fn from(err: FnError) -> Self {
Self::Fn(err)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IO(err.to_string())
}
}