Skip to main content

moqtap_trace/
error.rs

1/// Errors that can occur when reading or writing `.moqtrace` files.
2#[derive(Debug, thiserror::Error)]
3pub enum MoqTraceError {
4    /// I/O error from the underlying reader or writer.
5    #[error("io error: {0}")]
6    Io(#[from] std::io::Error),
7    /// CBOR encoding error.
8    #[error("cbor encode error: {0}")]
9    CborEncode(String),
10    /// CBOR decoding error.
11    #[error("cbor decode error: {0}")]
12    CborDecode(String),
13    /// File does not start with the expected `MOQTRACE` magic bytes.
14    #[error("invalid magic bytes")]
15    InvalidMagic,
16    /// File declares a format version this library does not support.
17    #[error("unsupported version: {0}")]
18    UnsupportedVersion(u32),
19    /// Header is missing required fields or contains invalid values.
20    #[error("invalid header: {0}")]
21    InvalidHeader(String),
22    /// Event has an unknown type or is missing required fields.
23    #[error("invalid event: {0}")]
24    InvalidEvent(String),
25}
26
27impl<T: std::fmt::Debug> From<ciborium::ser::Error<T>> for MoqTraceError {
28    fn from(e: ciborium::ser::Error<T>) -> Self {
29        MoqTraceError::CborEncode(format!("{e:?}"))
30    }
31}
32
33impl<T: std::fmt::Debug> From<ciborium::de::Error<T>> for MoqTraceError {
34    fn from(e: ciborium::de::Error<T>) -> Self {
35        MoqTraceError::CborDecode(format!("{e:?}"))
36    }
37}