timed_metadata/error.rs
1//! Crate error type.
2use alloc::string::String;
3use broadcast_core::timescale::Timescale;
4
5/// Errors produced by conversions and the [`crate::Timeline`] session.
6#[derive(Debug, thiserror::Error, Clone, PartialEq)]
7#[non_exhaustive]
8pub enum Error {
9 /// A wall-clock conversion was attempted without a [`crate::TimeAnchor`].
10 #[error("wall-clock conversion requires a TimeAnchor, but none was set")]
11 MissingAnchor,
12 /// SCTE 35 `emsg` cannot be version 0: ANSI/SCTE 214-1:2024 §7.7.1(2),
13 /// `private/specs-verified/scte/dash/scte-214-1-2024.md`.
14 #[error("SCTE 35 emsg version 0 is not allowed; supply a version 1 presentation_time")]
15 Scte35EmsgVersionZero,
16 /// `emsg_to_v0` was asked to write a SCTE 35 `emsg`, which 214-1 2024 §7.7.1(2) forbids.
17 #[error("SCTE 35 emsg cannot be converted to version 0 (ANSI/SCTE 214-1:2024 §7.7.1(2))")]
18 Scte35EmsgVersionZeroConversion,
19 /// An emsg presented to [`crate::convert::emsg_to_scte35`] is not a
20 /// SCTE-35 carriage scheme.
21 #[error("emsg scheme {scheme:?} is not a SCTE-35 carriage scheme")]
22 #[non_exhaustive]
23 UnsupportedScheme {
24 /// The `emsg` `scheme_id_uri` that was rejected, verbatim.
25 scheme: String,
26 },
27 /// SCTE-35 parse failure.
28 #[error("SCTE-35: {0}")]
29 Scte35(#[from] scte35_splice::Error),
30 /// emsg parse/serialize failure.
31 #[error("emsg: {0}")]
32 Emsg(#[from] isobmff::Error),
33 /// `EXT-X-DATERANGE` tag could not be parsed.
34 #[error("DATERANGE parse: {0}")]
35 AttrParse(String),
36 /// A SCTE-35-sourced event has no `id` (e.g. a `time_signal` cue with no
37 /// `segmentation_descriptor`), so it cannot be given a `DATERANGE` `ID`
38 /// (RFC 8216bis §4.4.5.1 requires unique IDs; emitting `ID=""` would
39 /// silently collide across cues).
40 #[error("SCTE-35 event has no id; cannot produce a DATERANGE ID")]
41 MissingEventId,
42 /// emsg ↔ SegmentTiming `timescale` mismatch.
43 #[error("emsg timescale ({emsg}) does not match SegmentTiming timescale ({timing})")]
44 #[non_exhaustive]
45 EmsgTimescaleMismatch {
46 /// The `timescale` declared by the `emsg` box.
47 emsg: Timescale,
48 /// The `timescale` declared by the DASH `SegmentTiming`.
49 timing: Timescale,
50 },
51 /// The emsg states a `timescale` of 0, which no time can be read in.
52 #[error("emsg timescale is 0")]
53 EmsgZeroTimescale,
54 /// v0 emsg cannot carry an event starting before the segment EPT.
55 #[error("presentation time precedes earliest presentation time; cannot express as v0 delta")]
56 EmsgPresentationTimeBeforeEpt,
57 /// v0 `presentation_time_delta` overflowed u32.
58 #[error("presentation_time_delta value {0} exceeds u32 max")]
59 EmsgDeltaOverflow(u64),
60 /// A v0 emsg's `earliest_presentation_time + presentation_time_delta`
61 /// overflowed `u64` (ISO/IEC 23009-1 §5.10.3.3); a wrapped value would
62 /// silently place the event near time zero.
63 #[error("earliest presentation time + presentation_time_delta overflows u64")]
64 EmsgPresentationTimeOverflow,
65 /// The emsg carries a `PresentationTime` variant this crate does not
66 /// know how to convert (the enum is `#[non_exhaustive]` upstream).
67 #[error("unsupported emsg PresentationTime variant")]
68 UnsupportedPresentationTime,
69 /// A `DATERANGE` attribute value (`ID`, `CLASS`, or a `SCTE35-*` hex
70 /// token) could not be represented as an RFC 8216 §4.2 quoted-string —
71 /// contains `"`, CR or LF (issue #1140 / audit r12-TM-W4): these values
72 /// are frequently sourced from an upstream SCTE-35 segmentation
73 /// descriptor's `segmentation_upid`, which is caller/network data, not
74 /// this crate's own.
75 #[error(transparent)]
76 HlsAttrValue(#[from] broadcast_hls::Error),
77 /// `DURATION`/`PLANNED-DURATION` was NaN, infinite, or negative (issue
78 /// #1140 / audit r13-BH-W4-class). RFC 8216 decimal-floating-point is
79 /// non-negative and finite.
80 #[error("{what} must be a finite, non-negative number of seconds, got {value}")]
81 #[non_exhaustive]
82 InvalidDuration {
83 /// Which attribute failed (`"DURATION"` or `"PLANNED-DURATION"`).
84 what: &'static str,
85 /// The offending value.
86 value: f64,
87 },
88 /// A wall-clock instant is outside the range RFC 3339 formatting supports
89 /// (years -9999..=9999).
90 #[error(
91 "epoch milliseconds {0} are outside the representable RFC 3339 range (years -9999..=9999)"
92 )]
93 TimestampOutOfRange(i64),
94}
95
96/// Crate result alias.
97pub type Result<T> = core::result::Result<T, Error>;