intrepid-core 0.3.0

Manage complex async business logic with ease
Documentation
use tower::BoxError;

use crate::{ExtractorError, PatternError};

/// A collection of errors that can occur in this crate.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// An error that occurs when extracting data from a frame.
    #[error(transparent)]
    ExtractorError(#[from] ExtractorError),
    /// An error that occurs when parsing.
    #[error(transparent)]
    ParsingError(#[from] ParsingError),
    /// An error that occurs when creating a frame.
    #[error(transparent)]
    FrameError(#[from] FrameError),
    /// An error that occurs when working with streams.
    #[error(transparent)]
    StreamError(#[from] StreamError),
}

/// An error that occurs when parsing data.
#[derive(Debug, thiserror::Error)]
#[error("an error occurred while parsing data: {0}")]
pub struct ParsingError(pub(crate) PatternError);

/// An error that occurs when creating a frame.
#[derive(Debug, thiserror::Error)]
#[error("an error occurred while creating a frame: {0}")]
pub struct FrameError(pub(crate) String);

/// An error that occurs when working with streams.
#[derive(Debug, thiserror::Error)]
#[error("an error occurred while working with streams: {0}")]
pub struct StreamError(pub(crate) BoxError);

impl From<Error> for crate::Frame {
    fn from(error: Error) -> Self {
        crate::Frame::Error(error.to_string().into())
    }
}