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