Skip to main content

m3u8_parser/m3u8/
validation.rs

1/// Represents different types of validation errors that can occur when processing an M3U8 playlist.
2///
3/// This enum captures specific validation issues that may arise when checking the conformity
4/// of a playlist to the M3U8 specification. Each variant represents a distinct error, providing
5/// context for what went wrong during validation.
6#[derive(Debug, PartialEq)]
7#[non_exhaustive]
8pub enum ValidationError {
9    /// Error indicating that the #EXTM3U tag is missing from the playlist.
10    MissingExtM3U,
11    /// Error indicating that #EXTM3U is not the first tag in the playlist.
12    ExtM3UNotFirst,
13    /// Error indicating that a tag that may occur only once is duplicated.
14    DuplicateTag(String),
15    /// Error indicating that Master Playlist and Media Playlist tags are mixed.
16    MixedPlaylistTypes,
17    /// Error indicating that a Media Playlist is missing EXT-X-TARGETDURATION.
18    MissingTargetDuration,
19    /// Error indicating that an EXT-X-STREAM-INF tag is not followed by a URI.
20    MissingVariantUri,
21    /// Error indicating that a stream rendition-group reference cannot be resolved.
22    UnresolvedRenditionGroup { attribute: String, group_id: String },
23    /// Error indicating that a tag requires a newer EXT-X-VERSION.
24    InsufficientVersion {
25        tag: String,
26        required: u8,
27        actual: u8,
28    },
29    /// Error indicating that a tag was removed in the playlist's protocol version.
30    RemovedTag { tag: String, removed_in: u8 },
31    /// Error indicating that a media segment exceeds EXT-X-TARGETDURATION.
32    SegmentDurationExceedsTarget { duration: f64, target_duration: u64 },
33
34    /// Error indicating that the specified version is outside 1 through 12,
35    /// the versions defined by draft-pantos-hls-rfc8216bis.
36    ///
37    /// # Arguments
38    ///
39    /// * `u8` - The invalid version number that was encountered.
40    InvalidVersion(u8),
41
42    /// Error indicating that the duration specified is invalid.
43    ///
44    /// # Arguments
45    ///
46    /// * `f64` - The invalid duration value that was encountered.
47    InvalidDuration(f64),
48
49    /// Error indicating that the target duration specified is invalid.
50    ///
51    /// # Arguments
52    ///
53    /// * `u64` - The invalid target duration value that was encountered.
54    InvalidTargetDuration(u64),
55
56    /// Error indicating that an invalid key method was specified.
57    ///
58    /// # Arguments
59    ///
60    /// * `String` - The invalid key method that was encountered.
61    InvalidKeyMethod(String),
62    /// Error indicating that key attributes are inconsistent with the selected method.
63    InvalidKeyAttributes(String),
64
65    /// Error indicating that the URI specified in a map tag is invalid.
66    InvalidMapUri,
67
68    /// Error indicating that the program date and time specified is invalid.
69    InvalidProgramDateTime,
70
71    /// Error indicating that the ID specified in a date range is invalid.
72    InvalidDateRangeId,
73
74    /// Error indicating that the start date specified in a date range is invalid.
75    InvalidDateRangeStartDate,
76
77    /// Error indicating that the end date specified in a date range is invalid.
78    InvalidDateRangeEndDate,
79
80    /// Error indicating that the planned duration specified in a date range is invalid.
81    ///
82    /// # Arguments
83    ///
84    /// * `f64` - The invalid planned duration value that was encountered in the date range.
85    InvalidDateRangePlannedDuration(f64),
86    /// Error indicating incompatible EXT-X-DATERANGE attributes.
87    InvalidDateRangeAttributes(String),
88
89    /// Error indicating that a media tag is missing required fields.
90    MissingMediaFields,
91
92    /// Error indicating that EXT-X-MEDIA attributes are inconsistent with its TYPE.
93    InvalidMediaAttributes(String),
94
95    /// Error indicating that a preload hint URI is invalid.
96    InvalidPreloadHintUri,
97
98    /// Error indicating that a rendition report URI is invalid.
99    InvalidRenditionReportUri,
100
101    /// Error indicating that a tag does not survive being written and read back,
102    /// typically because a string contains a newline or a double quote that would
103    /// alter the playlist's structure. Holds the tag as it would be written.
104    UnserializableTag(String),
105
106    /// Error indicating that a URI line is not preceded by EXTINF or EXT-X-STREAM-INF.
107    OrphanUri(String),
108
109    /// Error indicating that an EXT-X-DATERANGE ID is used more than once.
110    DuplicateDateRangeId(String),
111
112    /// Error indicating that two EXT-X-SESSION-DATA tags share a DATA-ID and LANGUAGE.
113    DuplicateSessionData {
114        id: String,
115        language: Option<String>,
116    },
117
118    /// Error indicating that EXT-X-PART is used without EXT-X-PART-INF.
119    MissingPartInf,
120
121    /// Error indicating that EXT-X-SERVER-CONTROL hold-back values are too short
122    /// for the playlist's target durations.
123    InvalidServerControl(String),
124
125    /// Error indicating that a tag must precede the first media segment but follows it.
126    TagAfterFirstSegment(String),
127
128    /// Error indicating that a segment's EXT-X-BYTERANGE has no offset but does not
129    /// follow a sub-range of the same resource. Holds the segment URI.
130    InvalidByteRange(String),
131}