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