Skip to main content

rtmp_runtime/
error.rs

1//! Error type for the RTMP ingest session engine.
2//!
3//! Structured [`thiserror`] errors covering the failure surface of the
4//! sans-IO engine: handshake framing (§5.2), chunk stream parsing (§5.3),
5//! message reassembly (§6), AMF0 decoding (`[AMF0]`), and session state-machine
6//! violations (§7.2) — see [`docs/rtmp.md`](../docs/rtmp.md).
7
8/// Errors produced by the RTMP ingest session engine.
9#[non_exhaustive]
10#[derive(Debug, thiserror::Error)]
11pub enum RtmpError {
12    /// Not enough input bytes were available to parse a complete structure
13    /// (handshake message, chunk header, or reassembled RTMP message).
14    #[error("buffer too short for {what}: need {need}, have {have}")]
15    BufferTooShort {
16        /// Number of bytes required to complete the parse.
17        need: usize,
18        /// Number of bytes actually available.
19        have: usize,
20        /// What was being parsed when the buffer ran out.
21        what: &'static str,
22    },
23
24    /// The input did not conform to the expected wire layout (bad handshake
25    /// version, invalid chunk `fmt`/CSID encoding, malformed AMF0 value, or
26    /// similar).
27    #[error("malformed {what}")]
28    Malformed {
29        /// What was being parsed when the malformed data was found.
30        what: &'static str,
31    },
32
33    /// An operation was attempted that is not valid in the session's current
34    /// state (e.g. a command received before the handshake completed, or
35    /// `publish` before `createStream`).
36    #[error("unexpected state: {what}")]
37    UnexpectedState {
38        /// Description of the state violation.
39        what: &'static str,
40    },
41
42    /// The input used a feature or value this engine does not (yet) support
43    /// (e.g. AMF3, an unrecognised command name).
44    #[error("unsupported: {what}")]
45    Unsupported {
46        /// What is unsupported.
47        what: &'static str,
48    },
49
50    /// A [`crate::chunk::Message`] was built with a `chunk_stream_id` outside
51    /// the basic header's encodable range (2..=65599, RTMP §5.3.1.1), so it
52    /// cannot be written.
53    #[error("chunk stream id {chunk_stream_id} is outside the encodable range 2..=65599")]
54    InvalidChunkStreamId {
55        /// The offending chunk stream id.
56        chunk_stream_id: u32,
57    },
58
59    /// A length or count did not fit the wire field it is written to
60    /// (#1129): a serializer that narrowed a `usize` with `as u32` (then
61    /// packed it into a 24-bit field) would have silently wrapped and
62    /// emitted a misframed chunk stream; this is returned instead.
63    #[error(transparent)]
64    FieldOverflow(#[from] broadcast_common::len::FieldOverflow),
65}