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 cannot read.
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    /// The stream ended part-way through an item — the file was truncated by
26    /// a crashed recorder or an interrupted transfer.
27    ///
28    /// Everything decoded before `offset` is valid and should be kept. Callers
29    /// holding a seekable or resumable source can look for the next segment
30    /// with [`resync_to_next_segment`](crate::reader::MoqTraceReader::resync_to_next_segment).
31    #[error("trace truncated: the item starting at byte offset {offset} is incomplete")]
32    Truncated {
33        /// Byte offset, counted from the start of the stream handed to the
34        /// reader, at which the incomplete item begins.
35        offset: u64,
36    },
37}
38
39impl<T: std::fmt::Debug> From<ciborium::ser::Error<T>> for MoqTraceError {
40    fn from(e: ciborium::ser::Error<T>) -> Self {
41        MoqTraceError::CborEncode(format!("{e:?}"))
42    }
43}
44
45impl<T: std::fmt::Debug> From<ciborium::de::Error<T>> for MoqTraceError {
46    fn from(e: ciborium::de::Error<T>) -> Self {
47        MoqTraceError::CborDecode(format!("{e:?}"))
48    }
49}