timed_metadata/error.rs
1//! Crate error type.
2use alloc::string::String;
3use broadcast_common::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 /// An emsg presented to [`crate::convert::emsg_to_scte35`] is not a
13 /// SCTE-35 carriage scheme.
14 #[error("emsg scheme {scheme:?} is not a SCTE-35 carriage scheme")]
15 UnsupportedScheme { scheme: String },
16 /// SCTE-35 parse failure.
17 #[error("SCTE-35: {0}")]
18 Scte35(#[from] scte35_splice::Error),
19 /// emsg parse/serialize failure.
20 #[error("emsg: {0}")]
21 Emsg(#[from] mp4_emsg::Error),
22 /// `EXT-X-DATERANGE` tag could not be parsed.
23 #[error("DATERANGE parse: {0}")]
24 AttrParse(String),
25 /// A SCTE-35-sourced event has no `id` (e.g. a `time_signal` cue with no
26 /// `segmentation_descriptor`), so it cannot be given a `DATERANGE` `ID`
27 /// (RFC 8216bis §4.4.5.1 requires unique IDs; emitting `ID=""` would
28 /// silently collide across cues).
29 #[error("SCTE-35 event has no id; cannot produce a DATERANGE ID")]
30 MissingEventId,
31 /// emsg ↔ SegmentTiming `timescale` mismatch.
32 #[error("emsg timescale ({emsg}) does not match SegmentTiming timescale ({timing})")]
33 EmsgTimescaleMismatch { emsg: Timescale, timing: Timescale },
34 /// v0 emsg cannot carry an event starting before the segment EPT.
35 #[error("presentation time precedes earliest presentation time; cannot express as v0 delta")]
36 EmsgPresentationTimeBeforeEpt,
37 /// v0 `presentation_time_delta` overflowed u32.
38 #[error("presentation_time_delta value {0} exceeds u32 max")]
39 EmsgDeltaOverflow(u64),
40 /// A v0 emsg's `earliest_presentation_time + presentation_time_delta`
41 /// overflowed `u64` (ISO/IEC 23009-1 §5.10.3.3); a wrapped value would
42 /// silently place the event near time zero.
43 #[error("earliest presentation time + presentation_time_delta overflows u64")]
44 EmsgPresentationTimeOverflow,
45 /// The emsg carries a `PresentationTime` variant this crate does not
46 /// know how to convert (the enum is `#[non_exhaustive]` upstream).
47 #[error("unsupported emsg PresentationTime variant")]
48 UnsupportedPresentationTime,
49 /// A `DATERANGE` attribute value (`ID`, `CLASS`, or a `SCTE35-*` hex
50 /// token) could not be represented as an RFC 8216 §4.2 quoted-string —
51 /// contains `"`, CR or LF (issue #1140 / audit r12-TM-W4): these values
52 /// are frequently sourced from an upstream SCTE-35 segmentation
53 /// descriptor's `segmentation_upid`, which is caller/network data, not
54 /// this crate's own.
55 #[error(transparent)]
56 HlsAttrValue(#[from] broadcast_hls::Error),
57 /// `DURATION`/`PLANNED-DURATION` was NaN, infinite, or negative (issue
58 /// #1140 / audit r13-BH-W4-class). RFC 8216 decimal-floating-point is
59 /// non-negative and finite.
60 #[error("{what} must be a finite, non-negative number of seconds, got {value}")]
61 InvalidDuration {
62 /// Which attribute failed (`"DURATION"` or `"PLANNED-DURATION"`).
63 what: &'static str,
64 /// The offending value.
65 value: f64,
66 },
67 /// A wall-clock instant is outside the range RFC 3339 formatting supports
68 /// (years -9999..=9999).
69 #[error(
70 "epoch milliseconds {0} are outside the representable RFC 3339 range (years -9999..=9999)"
71 )]
72 TimestampOutOfRange(i64),
73}
74
75/// Crate result alias.
76pub type Result<T> = core::result::Result<T, Error>;