uriplaylistbin: use thiserror

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1232>
This commit is contained in:
Guillaume Desmottes 2023-05-04 11:55:59 +02:00
parent 432de060ea
commit f4604e1c58
2 changed files with 4 additions and 24 deletions

View file

@ -13,6 +13,7 @@ gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/g
once_cell = "1.0"
anyhow = "1"
clap = { version = "4", optional = true, features = ["derive"] }
thiserror = "1"
[dev-dependencies]
gst-app = { package = "gstreamer-app", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }

View file

@ -26,35 +26,14 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
/// how many items are allowed to be prepared and waiting in the pipeline
const MAX_STREAMING_ITEMS: usize = 2;
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
enum PlaylistError {
#[error("plugin missing: {error}")]
PluginMissing { error: anyhow::Error },
#[error("{item:?} failed: {error}")]
ItemFailed { error: anyhow::Error, item: Item },
}
impl std::fmt::Display for PlaylistError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PlaylistError::PluginMissing { error } => {
write!(f, "{error}")
}
PlaylistError::ItemFailed { error, item } => {
write!(f, "{} (URI: {})", error, item.uri())
}
}
}
}
impl std::error::Error for PlaylistError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
PlaylistError::PluginMissing { error } | PlaylistError::ItemFailed { error, .. } => {
Some(error.as_ref())
}
}
}
}
/// Number of different streams currently handled by the element
#[derive(Debug, Default, Clone, PartialEq)]
struct StreamsTopology {