Skip to main content

ssai_runtime/
error.rs

1//! Crate error type.
2
3use alloc::string::String;
4
5/// Errors produced by session, decision, splice-conditioning, and playlist
6/// rendering operations.
7#[derive(Debug, thiserror::Error, Clone, PartialEq)]
8#[non_exhaustive]
9pub enum Error {
10    /// [`crate::splice::condition_splice_point`] found no candidate boundary
11    /// within the caller's tolerance.
12    #[error(
13        "no candidate splice boundary within {tolerance_ticks} ticks of requested pts \
14         {requested_pts} (nearest delta {nearest_delta_ticks} ticks)"
15    )]
16    NoAlignedBoundary {
17        /// The cue's nominal target.
18        requested_pts: u64,
19        /// The caller's maximum acceptable drift.
20        tolerance_ticks: u64,
21        /// The delta of the nearest candidate actually found.
22        nearest_delta_ticks: u64,
23    },
24    /// [`crate::splice::condition_splice_point`] was called with an empty
25    /// candidate slice.
26    #[error("no candidate splice boundaries supplied")]
27    NoCandidates,
28    /// The base playlist carries no `#EXT-X-PROGRAM-DATE-TIME` tag, which
29    /// RFC 8216bis §4.4.5.1 requires of any playlist containing an
30    /// `EXT-X-DATERANGE` (issue #1125 / audit r14-SSAI-W3).
31    #[error("base playlist has no EXT-X-PROGRAM-DATE-TIME; an EXT-X-DATERANGE requires one")]
32    MissingProgramDateTime,
33    /// An interstitial asset source was neither `X-ASSET-URI` nor
34    /// `X-ASSET-LIST` — Appendix D §D.2 requires exactly one.
35    #[error("interstitial asset source must be exactly one of X-ASSET-URI or X-ASSET-LIST")]
36    InvalidAssetSource,
37    /// [`crate::session::SessionStore`] has no record for the session.
38    #[error("session {0:?} has no active ad break")]
39    NoActiveBreak(String),
40    /// [`crate::session::SessionStore::begin_break`] was called for a
41    /// session that already has an unresumed break.
42    #[error("session {0:?} already has an active ad break")]
43    BreakAlreadyActive(String),
44    /// [`crate::session::SessionStore::resume`] was called for a session whose
45    /// break was already resumed.
46    #[error("session {0:?} has already resumed its ad break")]
47    BreakAlreadyResumed(String),
48    /// [`crate::session::SessionStore::begin_break`] was called for a new
49    /// session while the store was already tracking its maximum.
50    #[error("session store is full ({max} sessions)")]
51    SessionStoreFull {
52        /// The store's bound.
53        max: usize,
54    },
55    /// An Interstitial `EXT-X-DATERANGE` tag line failed to parse.
56    #[error("interstitial DATERANGE parse: {0}")]
57    TagParse(String),
58    /// An attribute value supplied by the [`crate::decision::AdDecisionProvider`]
59    /// (a `URI`, an `ID`, or any other ad-server-controlled string) could not
60    /// be represented as an RFC 8216 §4.2 quoted-string — contains `"`, CR or
61    /// LF (issue #1140 / audit r14-SSAI-W1): rendering an ad-decision
62    /// response straight into the playlist without validation let a `"` or
63    /// a newline in, e.g., an ad URI terminate the attribute list and inject
64    /// arbitrary tag lines into every viewer's session playlist.
65    #[error(transparent)]
66    HlsAttrValue(#[from] broadcast_hls::Error),
67    /// A `DURATION`/`X-RESUME-OFFSET`/`X-PLAYOUT-LIMIT` value was NaN,
68    /// infinite, or negative (issue #1140 / audit r14-SSAI-W4). RFC 8216
69    /// decimal-floating-point is non-negative and finite; `NaN as i64 == 0`
70    /// let a NaN duration render as the bare token `NaN`.
71    #[error("{what} must be a finite, non-negative number of seconds, got {value}")]
72    InvalidDuration {
73        /// Which attribute failed (`"DURATION"`, `"X-RESUME-OFFSET"`, …).
74        what: &'static str,
75        /// The offending value.
76        value: f64,
77    },
78}
79
80/// Crate result alias.
81pub type Result<T> = core::result::Result<T, Error>;