From 3a98bacd397c81a494f8283d83630a3ae55f5a1d Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 4 May 2023 11:55:59 +0200 Subject: [PATCH] uriplaylistbin: use thiserror Part-of: --- utils/uriplaylistbin/Cargo.toml | 1 + .../uriplaylistbin/src/uriplaylistbin/imp.rs | 27 +++---------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/utils/uriplaylistbin/Cargo.toml b/utils/uriplaylistbin/Cargo.toml index b3093102..d398c634 100644 --- a/utils/uriplaylistbin/Cargo.toml +++ b/utils/uriplaylistbin/Cargo.toml @@ -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", branch = "0.19", version = "0.19" } diff --git a/utils/uriplaylistbin/src/uriplaylistbin/imp.rs b/utils/uriplaylistbin/src/uriplaylistbin/imp.rs index c3de6202..67625207 100644 --- a/utils/uriplaylistbin/src/uriplaylistbin/imp.rs +++ b/utils/uriplaylistbin/src/uriplaylistbin/imp.rs @@ -26,35 +26,14 @@ static CAT: Lazy = 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 {