#[derive(Debug)]
pub enum Error {
Codec(String),
ComponentNotFound(String, String),
MissingInput(String),
EndOfOutput(String),
Component(String),
ResponseMissing(String),
}
#[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 From<ComponentError> for Error {
fn from(e: ComponentError) -> Self {
Self::Component(e.to_string())
}
}
impl From<String> for Error {
fn from(e: String) -> Self {
Error::Component(e)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ComponentNotFound(v, valid) => write!(f, "Component '{}' not found. Valid components are: {}", v, valid),
Error::Codec(e) => write!(f, "Codec error: {}", e),
Error::MissingInput(v) => write!(f, "Missing input for port '{}'", v),
Error::Component(v) => write!(f, "{}", v),
Error::EndOfOutput(v) => write!(f, "No output available for port '{}'", v),
Error::ResponseMissing(v) => write!(f, "No response received for port '{}'", v),
}
}
}
impl std::error::Error for Error {}