use std::error; /// An error within an import session. #[derive(thiserror::Error, Debug)] pub enum Error { /// A timeout was reached. #[error("{0}")] Timeout(String), /// Some common error. #[error("{msg}")] Other { /// The error message. msg: String, #[source] source: Option>, }, /// Something unexpected happened. #[error("{msg}")] Unexpected { /// The error message. msg: String, #[source] source: Option>, }, } impl Error { /// Create a new error with an explicit source. pub(super) fn os(source: impl error::Error + Send + Sync + 'static) -> Self { Self::Unexpected { msg: format!("An error has happened: {}", source), source: Some(Box::new(source)), } } /// Create a new unexpected error without an explicit source. pub(super) fn u(msg: String) -> Self { Self::Unexpected { msg, source: None } } /// Create a new unexpected error with an explicit source. pub(super) fn us(source: impl error::Error + Send + Sync + 'static) -> Self { Self::Unexpected { msg: format!("An unexpected error has happened: {}", source), source: Some(Box::new(source)), } } } impl From for Error { fn from(err: tokio::sync::oneshot::error::RecvError) -> Self { Self::us(err) } } impl From for Error { fn from(err: gstreamer::glib::Error) -> Self { Self::us(err) } } impl From for Error { fn from(err: gstreamer::glib::BoolError) -> Self { Self::us(err) } } impl From for Error { fn from(err: gstreamer::StateChangeError) -> Self { Self::us(err) } } impl From for Error { fn from(err: std::io::Error) -> Self { Self::us(err) } } pub type Result = std::result::Result;