intrepid_core/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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())
    }
}