rsrs_core/
error.rs

1use thiserror::Error;
2
3/// A type alias for [`Result<T, [`Error>`]`].
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// A type to represent all possible errors that can occur when using this
7/// library.
8#[derive(Debug, Error)]
9pub enum Error {
10    /// An error that can occur when encoding/decoding a frame.
11    #[error("encoding/decoding error: {0}")]
12    Codec(#[from] recode::Error),
13
14    /// Invalid value was provided for a field at `path`.
15    #[error("invalid value for `$path`: {message}")]
16    InvalidValue {
17        path: &'static str,
18        message: &'static str,
19    },
20
21    /// A value of a required field `field` of frame of type `frame_type` is
22    /// missing.
23    #[error("missing value of `{frame_type} :: {field}'")]
24    MissingFieldValue {
25        frame_type: crate::FrameType,
26        field: &'static str,
27    },
28
29    /// A frame has flags that are not allowed for its type.
30    #[error("unexpected flag `{flag:10b}' in `{frame_type}': {message}")]
31    UnexpectedFlag {
32        flag: crate::FrameFlags,
33        frame_type: crate::FrameType,
34        message: &'static str,
35    },
36
37    /// A frame is missing flags that are required for its type.
38    #[error("missing flag `{flag}' in `{frame_type}': {message}")]
39    MissingFlag {
40        flag: crate::FrameFlags,
41        frame_type: crate::FrameType,
42        message: &'static str,
43    },
44
45    #[error("invalid frame (`IGNORE` flag set): {0}")]
46    IgnoreableFrame(Box<Error>),
47}
48
49impl From<std::convert::Infallible> for Error {
50    fn from(_: std::convert::Infallible) -> Self {
51        unreachable!()
52    }
53}