hang/error.rs
1/// Error types for the hang media library.
2///
3/// This enum represents all possible errors that can occur when working with
4/// hang media streams, codecs, and containers.
5#[derive(Debug, thiserror::Error, Clone)]
6#[non_exhaustive]
7pub enum Error {
8 /// An error from the underlying MoQ transport layer.
9 #[error("moq error: {0}")]
10 Moq(#[from] moq_net::Error),
11
12 /// JSON serialization/deserialization error.
13 #[error("json error: {0}")]
14 Json(String),
15
16 /// A catalog uses one rendition ID for both a video and an audio rendition.
17 #[error("catalog rendition ID is both video and audio: {0}")]
18 DuplicateRendition(String),
19
20 /// A catalog needs a newer moq-hang draft than this reader implements.
21 #[error("unsupported catalog version {0}: upgrade to read it")]
22 UnsupportedVersion(u64),
23
24 /// A catalog broadcast reference escapes its root.
25 #[error("catalog broadcast reference escapes the root: {0}")]
26 EscapingBroadcast(String),
27
28 /// The specified codec is invalid or malformed.
29 #[error("invalid codec")]
30 InvalidCodec,
31
32 /// Failed to parse an integer value.
33 #[error("expected int")]
34 ExpectedInt(#[from] std::num::ParseIntError),
35
36 /// The timestamp is too large.
37 #[error("timestamp overflow")]
38 TimestampOverflow(#[from] moq_net::TimeOverflow),
39
40 /// A track with this name already exists in the catalog.
41 #[error("duplicate track: {0}")]
42 Duplicate(String),
43
44 /// A catalog timescale is zero, so no timestamp can be expressed in it.
45 #[error("invalid timescale: {0}")]
46 InvalidTimescale(u64),
47
48 /// A catalog wall-clock value is outside the JSON-safe integer range.
49 #[error("invalid wall clock: {0}")]
50 InvalidWall(u64),
51
52 /// The shared video rotation is not a finite number.
53 #[error("video rotation must be finite")]
54 InvalidVideoRotation,
55
56 /// An equirectangular video's field of view is outside (0, 360] degrees.
57 #[error("video field of view {0} must be in (0, 360] degrees")]
58 InvalidFieldOfView(f64),
59
60 /// An ambisonic audio rendition's channel count is not a square of at least 4.
61 #[error("ambisonic audio needs a square channel count of at least 4, not {0}")]
62 InvalidAmbisonicChannels(u32),
63
64 /// A catalog field that counts something is zero, such as a picture dimension or sample rate.
65 #[error("catalog {0} must not be zero")]
66 Zero(&'static str),
67
68 /// An application catalog section's name collides with a member either catalog reserves.
69 #[error("reserved catalog section: {0}")]
70 ReservedSection(String),
71}
72
73/// A Result type alias for hang operations.
74///
75/// This is used throughout the hang crate as a convenient shorthand
76/// for `std::result::Result<T, hang::Error>`.
77pub type Result<T> = std::result::Result<T, Error>;
78
79// Foreign errors are flattened to their message so they stay out of this crate's public API.
80impl From<serde_json::Error> for Error {
81 fn from(err: serde_json::Error) -> Self {
82 Error::Json(err.to_string())
83 }
84}