intrepid_core/
errors.rs

1use tower::BoxError;
2
3use crate::{ExtractorError, PatternError};
4
5/// A collection of errors that can occur in this crate.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// An error that occurs when extracting data from a frame.
9    #[error(transparent)]
10    ExtractorError(#[from] ExtractorError),
11    /// An error that occurs when parsing.
12    #[error(transparent)]
13    ParsingError(#[from] ParsingError),
14    /// An error that occurs when creating a frame.
15    #[error(transparent)]
16    FrameError(#[from] FrameError),
17    /// An error that occurs when working with streams.
18    #[error(transparent)]
19    StreamError(#[from] StreamError),
20}
21
22/// An error that occurs when parsing data.
23#[derive(Debug, thiserror::Error)]
24#[error("an error occurred while parsing data: {0}")]
25pub struct ParsingError(pub(crate) PatternError);
26
27/// An error that occurs when creating a frame.
28#[derive(Debug, thiserror::Error)]
29#[error("an error occurred while creating a frame: {0}")]
30pub struct FrameError(pub(crate) String);
31
32/// An error that occurs when working with streams.
33#[derive(Debug, thiserror::Error)]
34#[error("an error occurred while working with streams: {0}")]
35pub struct StreamError(pub(crate) BoxError);
36
37impl From<Error> for crate::Frame {
38    fn from(error: Error) -> Self {
39        crate::Frame::Error(error.to_string().into())
40    }
41}