#[derive(Debug)]
pub enum Error {
HostError(String),
Codec(wasmflow_codec::Error),
Async,
Protocol(Box<dyn std::error::Error + Send + Sync>),
DispatcherNotSet,
}
impl From<wasmflow_codec::Error> for Error {
fn from(v: wasmflow_codec::Error) -> Self {
Self::Codec(v)
}
}
#[derive(Debug)]
pub struct ComponentError(String);
impl ComponentError {
pub fn new<T: std::fmt::Display>(message: T) -> Self {
Self(message.to_string())
}
}
impl std::error::Error for ComponentError {}
impl std::fmt::Display for ComponentError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::HostError(v) => write!(f, "Error executing host call: {}", v),
Error::Codec(e) => write!(f, "{}", e),
Error::Protocol(e) => write!(f, "Protocol error: {}", e),
Error::Async => write!(f, "Async runtime error"),
Error::DispatcherNotSet => write!(f, "Dispatcher not set before host call"),
}
}
}
impl std::error::Error for Error {}