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 `private/specs-verified/rtmp/rtmp-runtime/rtmp.md`.
7
8/// Errors produced by the RTMP ingest session engine.
9#[non_exhaustive]
10#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
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(transparent)]
15 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
16
17 /// The input did not conform to the expected wire layout (bad handshake
18 /// version, invalid chunk `fmt`/CSID encoding, malformed AMF0 value, or
19 /// similar).
20 #[error("malformed {what}")]
21 Malformed {
22 /// What was being parsed when the malformed data was found.
23 what: &'static str,
24 },
25
26 /// An operation was attempted that is not valid in the session's current
27 /// state (e.g. a command received before the handshake completed, or
28 /// `publish` before `createStream`).
29 #[error("unexpected state: {what}")]
30 UnexpectedState {
31 /// Description of the state violation.
32 what: &'static str,
33 },
34
35 /// The input used a feature or value this engine does not (yet) support
36 /// (e.g. AMF3, an unrecognised command name).
37 #[error("unsupported: {what}")]
38 Unsupported {
39 /// What is unsupported.
40 what: &'static str,
41 },
42
43 /// A [`crate::chunk::Message`] was built with a `chunk_stream_id` outside
44 /// the basic header's encodable range (2..=65599, RTMP §5.3.1.1), so it
45 /// cannot be written.
46 #[error("chunk stream id {chunk_stream_id} is outside the encodable range 2..=65599")]
47 InvalidChunkStreamId {
48 /// The offending chunk stream id.
49 chunk_stream_id: u32,
50 },
51
52 /// A length or count did not fit the wire field it is written to
53 /// (#1129): a serializer that narrowed a `usize` with `as u32` (then
54 /// packed it into a 24-bit field) would have silently wrapped and
55 /// emitted a misframed chunk stream; this is returned instead.
56 #[error(transparent)]
57 FieldOverflow(#[from] broadcast_common::error::FieldOverflow),
58
59 /// The output buffer passed to `serialize_into` was smaller than
60 /// `serialized_len()`.
61 #[error(transparent)]
62 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
63}