Skip to main content

rtsp_runtime/
error.rs

1//! Error types for the RTSP session engine.
2//!
3//! Structured [`thiserror`] errors covering the failure surface of the sans-IO
4//! engine: RTSP message parse/serialize, state-machine violations (RFC 2326
5//! Appendix A — see [`docs/state-machines.md`](../docs/state-machines.md)),
6//! CSeq correlation, missing/invalid `Session`, `Transport` header parsing
7//! (§12.39 — [`docs/transport-header.md`](../docs/transport-header.md)),
8//! interleaved framing (§10.12 — [`docs/interleaved-framing.md`](../docs/interleaved-framing.md)),
9//! and authentication (§14 — [`docs/auth.md`](../docs/auth.md)).
10
11use crate::Method;
12use crate::state::SessionState;
13
14/// Result alias for the engine's fallible operations.
15pub type Result<T> = core::result::Result<T, Error>;
16
17/// Errors produced by the RTSP session engine.
18#[non_exhaustive]
19#[derive(Debug, thiserror::Error)]
20pub enum Error {
21    /// The RTSP message could not be parsed by the underlying `rtsp-types` codec.
22    #[error("failed to parse RTSP message: {0}")]
23    MessageParse(String),
24
25    /// The RTSP message could not be serialized by the underlying codec.
26    #[error("failed to serialize RTSP message: {0}")]
27    MessageWrite(String),
28
29    /// A method was invoked (client) or received (server) that is not permitted
30    /// in the current session state. The server maps this to `455 Method Not
31    /// Valid In This State` (RFC 2326 §11.3.6, Appendix A).
32    #[error("method {method:?} not valid in state {state:?}")]
33    MethodNotValidInState {
34        /// The offending method.
35        method: Method,
36        /// The state the object was in when the method was attempted.
37        state: SessionState,
38    },
39
40    /// A response arrived carrying a `CSeq` that does not match any outstanding
41    /// request.
42    #[error("no pending request for CSeq {0}")]
43    UnknownCSeq(u32),
44
45    /// A response arrived with no parseable `CSeq` header.
46    #[error("response is missing a CSeq header")]
47    MissingCSeq,
48
49    /// An operation required an established session id but none was negotiated
50    /// (no SETUP response has been processed yet).
51    #[error("no session established (SETUP not completed)")]
52    MissingSession,
53
54    /// The `Transport` header value could not be parsed per RFC 2326 §12.39.
55    #[error("invalid Transport header: {0}")]
56    TransportParse(String),
57
58    /// An interleaved `$` frame was malformed (RFC 2326 §10.12).
59    #[error("invalid interleaved frame: {0}")]
60    InterleavedFrame(String),
61
62    /// Authentication failed: no credentials were configured, the challenge
63    /// could not be parsed, or the digest computation failed (RFC 2326 §14).
64    #[error("authentication failure: {0}")]
65    Auth(String),
66
67    /// The request required a request URI but none was set.
68    #[error("request URI required but not set")]
69    MissingRequestUri,
70
71    /// A socket IO operation failed in the async adapter (feature `tokio`).
72    #[error("socket IO error: {0}")]
73    Io(String),
74
75    /// A TLS operation failed in the async adapter (feature `tls`): bad server
76    /// name, handshake, or certificate configuration (`rtsps://`, RFC 2326 §19).
77    #[error("TLS error: {0}")]
78    Tls(String),
79}