Skip to main content

moq_rtc/
error.rs

1/// Errors produced by the WebRTC <-> MoQ gateway.
2#[derive(Debug, thiserror::Error)]
3#[non_exhaustive]
4pub enum Error {
5	/// An SDP offer or answer failed to parse or was missing something required.
6	#[error("invalid SDP: {0}")]
7	InvalidSdp(String),
8
9	/// The negotiated payload used a codec this gateway can't bridge to MoQ.
10	#[error("unsupported codec: {0}")]
11	UnsupportedCodec(String),
12
13	/// No live session matched the resource id (e.g. a DELETE for an unknown id).
14	#[error("session not found")]
15	SessionNotFound,
16
17	/// The peer closed the session; the media session ended without a failure.
18	#[error("session closed")]
19	SessionClosed,
20
21	/// ICE connectivity was not established before the establishment deadline.
22	#[error("ICE did not connect before the establishment deadline")]
23	IceTimeout,
24
25	/// A broadcast did not produce a catalog before the negotiation deadline.
26	#[error("catalog did not arrive before the negotiation deadline")]
27	CatalogTimeout,
28
29	/// The catalog track closed before publishing its first snapshot.
30	#[error("catalog closed before its first snapshot")]
31	CatalogClosed,
32
33	/// The catalog has no rendition this gateway can send over WebRTC.
34	#[error("catalog has no WebRTC-compatible renditions")]
35	NoRenditions,
36
37	/// The WebRTC engine produced no SDP changes for an offer.
38	#[error("no SDP changes to apply")]
39	NoSdpChanges,
40
41	/// I/O error on the media socket (bind, send, or receive).
42	#[error("io error: {0}")]
43	Io(#[from] std::io::Error),
44
45	/// Error from the underlying moq-net transport.
46	#[error("moq error: {0}")]
47	Moq(#[from] moq_net::Error),
48
49	/// Error from the moq-mux import/export layer bridging RTP and MoQ.
50	#[error("mux error: {0}")]
51	Mux(#[from] moq_mux::Error),
52
53	/// HTTP transport failed while dialing a WHIP or WHEP endpoint.
54	#[error("http error: {0}")]
55	Http(std::sync::Arc<reqwest::Error>),
56
57	/// A WHIP or WHEP endpoint rejected the HTTP request.
58	#[error("HTTP endpoint returned status {0}")]
59	HttpStatus(u16),
60
61	/// Error from the WebRTC engine (SDP negotiation, DTLS, media state).
62	#[error("rtc error: {0}")]
63	Rtc(String),
64
65	/// Error feeding a received UDP datagram into the WebRTC engine.
66	#[error("rtc input error: {0}")]
67	RtcInput(String),
68
69	/// An internal video bridge could not be initialized.
70	#[error("video bridge initialization failed")]
71	BridgeFailed,
72}
73
74impl From<reqwest::Error> for Error {
75	fn from(err: reqwest::Error) -> Self {
76		Self::Http(std::sync::Arc::new(err))
77	}
78}
79
80impl Error {
81	pub(crate) fn rtc(err: impl std::fmt::Display) -> Self {
82		Self::Rtc(err.to_string())
83	}
84
85	pub(crate) fn rtc_input(err: impl std::fmt::Display) -> Self {
86		Self::RtcInput(err.to_string())
87	}
88}
89
90/// Convenience alias for results from the WebRTC <-> MoQ gateway.
91pub type Result<T> = std::result::Result<T, Error>;