Skip to main content

libobs_simple/
error.rs

1use std::fmt::Display;
2
3use display_info::error::DIError;
4
5/// Error type for libobs-simple operations.
6#[derive(Debug)]
7pub enum ObsSimpleError {
8    /// The underlying libobs-wrapper error
9    WrapperError(libobs_wrapper::utils::ObsError),
10    /// Feature is not available on this system
11    FeatureNotAvailable(&'static str),
12    /// Error from display-info crate
13    DisplayInfoError(DIError),
14    /// Error from window helper
15    #[cfg(feature = "window-list")]
16    WindowHelperError(libobs_window_helper::WindowHelperError),
17}
18
19impl Display for ObsSimpleError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            ObsSimpleError::WrapperError(e) => write!(f, "OBS wrapper error: {}", e),
23            ObsSimpleError::FeatureNotAvailable(msg) => write!(f, "Feature not available: {}", msg),
24            ObsSimpleError::DisplayInfoError(e) => write!(f, "Display info error: {}", e),
25            #[cfg(feature = "window-list")]
26            ObsSimpleError::WindowHelperError(e) => write!(f, "Window helper error: {}", e),
27        }
28    }
29}
30
31impl std::error::Error for ObsSimpleError {}
32
33impl From<libobs_wrapper::utils::ObsError> for ObsSimpleError {
34    fn from(err: libobs_wrapper::utils::ObsError) -> Self {
35        ObsSimpleError::WrapperError(err)
36    }
37}
38
39#[cfg(feature = "window-list")]
40impl From<libobs_window_helper::WindowHelperError> for ObsSimpleError {
41    fn from(err: libobs_window_helper::WindowHelperError) -> Self {
42        ObsSimpleError::WindowHelperError(err)
43    }
44}