use std::fmt;
#[derive(Debug, Clone)]
pub struct SourceName(String);
impl SourceName {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self(name.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for SourceName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug)]
pub struct SourceError {
source_name: SourceName,
detail: String,
}
impl SourceError {
#[must_use]
pub fn new(source_name: SourceName, detail: impl Into<String>) -> Self {
Self {
source_name,
detail: detail.into(),
}
}
#[must_use]
pub fn source_name(&self) -> &SourceName {
&self.source_name
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for SourceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "source '{}': {}", self.source_name, self.detail)
}
}
impl std::error::Error for SourceError {}
#[derive(Debug)]
pub struct HydrationError {
detail: String,
}
impl HydrationError {
#[must_use]
pub fn new(detail: impl Into<String>) -> Self {
Self {
detail: detail.into(),
}
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for HydrationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "hydration: {}", self.detail)
}
}
impl std::error::Error for HydrationError {}
#[derive(Debug)]
pub struct FilterError {
detail: String,
}
impl FilterError {
#[must_use]
pub fn new(detail: impl Into<String>) -> Self {
Self {
detail: detail.into(),
}
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for FilterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "filter: {}", self.detail)
}
}
impl std::error::Error for FilterError {}
#[derive(Debug)]
pub struct ScoringError {
detail: String,
}
impl ScoringError {
#[must_use]
pub fn new(detail: impl Into<String>) -> Self {
Self {
detail: detail.into(),
}
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for ScoringError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "scoring: {}", self.detail)
}
}
impl std::error::Error for ScoringError {}
#[derive(Debug)]
pub struct SelectionError {
detail: String,
}
impl SelectionError {
#[must_use]
pub fn new(detail: impl Into<String>) -> Self {
Self {
detail: detail.into(),
}
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for SelectionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "selection: {}", self.detail)
}
}
impl std::error::Error for SelectionError {}
#[derive(Debug)]
pub struct SideEffectError {
detail: String,
}
impl SideEffectError {
#[must_use]
pub fn new(detail: impl Into<String>) -> Self {
Self {
detail: detail.into(),
}
}
#[must_use]
pub fn detail(&self) -> &str {
&self.detail
}
}
impl fmt::Display for SideEffectError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "side effect: {}", self.detail)
}
}
impl std::error::Error for SideEffectError {}
#[derive(Debug)]
pub enum PipelineError {
Source(SourceError),
Hydration(HydrationError),
Filter(FilterError),
Scoring(ScoringError),
Selection(SelectionError),
SideEffect(SideEffectError),
}
impl fmt::Display for PipelineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Source(e) => write!(f, "pipeline error: {e}"),
Self::Hydration(e) => write!(f, "pipeline error: {e}"),
Self::Filter(e) => write!(f, "pipeline error: {e}"),
Self::Scoring(e) => write!(f, "pipeline error: {e}"),
Self::Selection(e) => write!(f, "pipeline error: {e}"),
Self::SideEffect(e) => write!(f, "pipeline error: {e}"),
}
}
}
impl std::error::Error for PipelineError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Source(e) => Some(e),
Self::Hydration(e) => Some(e),
Self::Filter(e) => Some(e),
Self::Scoring(e) => Some(e),
Self::Selection(e) => Some(e),
Self::SideEffect(e) => Some(e),
}
}
}
impl From<SourceError> for PipelineError {
fn from(e: SourceError) -> Self {
Self::Source(e)
}
}
impl From<HydrationError> for PipelineError {
fn from(e: HydrationError) -> Self {
Self::Hydration(e)
}
}
impl From<FilterError> for PipelineError {
fn from(e: FilterError) -> Self {
Self::Filter(e)
}
}
impl From<ScoringError> for PipelineError {
fn from(e: ScoringError) -> Self {
Self::Scoring(e)
}
}
impl From<SelectionError> for PipelineError {
fn from(e: SelectionError) -> Self {
Self::Selection(e)
}
}
impl From<SideEffectError> for PipelineError {
fn from(e: SideEffectError) -> Self {
Self::SideEffect(e)
}
}