libobs_wrapper\utils/
error.rs

1use std::fmt::Display;
2
3use crate::enums::ObsResetVideoStatus;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum ObsBootstrapError {
7    GeneralError(String),
8    DownloadError(String),
9    ExtractError(String),
10}
11
12/// Error type for OBS function calls.
13#[derive(Clone, Debug, PartialEq, Eq)]
14pub enum ObsError {
15    /// The `obs_startup` function failed on libobs.
16    Failure,
17    /// Failed to lock mutex describing whether there is a
18    /// thread using libobs or not. Report to crate maintainer.
19    MutexFailure,
20    /// Some or no thread is already using libobs. This is a bug!
21    ThreadFailure,
22    /// Unable to reset video.
23    ResetVideoFailure(ObsResetVideoStatus),
24    /// Unable to bootstrap OBS for downloading and installing
25    BootstrapperFailure(ObsBootstrapError),
26    /// Unable to reset video because the program attempted to
27    /// change the graphics module. This is a bug!
28    ResetVideoFailureGraphicsModule,
29    /// The function returned a null pointer, often indicating
30    /// an error with creating the object of the requested
31    /// pointer.
32    NullPointer,
33    OutputAlreadyActive,
34    OutputStartFailure(Option<String>),
35    OutputStopFailure(Option<String>),
36    OutputNotFound,
37    SourceNotFound,
38
39    /// Native error from the Windows API when creating a display
40    DisplayCreationError(String),
41
42    OutputSaveBufferFailure(String),
43
44    /// The obs thread couldn't be called
45    InvocationError(String),
46
47    JsonParseError,
48    /// Couldn't get the sender of the signal
49    NoSenderError,
50}
51
52impl Display for ObsError {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        write!(f, "OBS Error: ")?;
55
56        match self {
57            ObsError::Failure => write!(f, "`obs-startup` function failed on libobs"),
58            ObsError::MutexFailure => write!(f, "Failed to lock mutex describing whether there is a thread using libobs or not. Report to crate maintainer."),
59            ObsError::ThreadFailure => write!(f, "Some or no thread is already using libobs. This is a bug!"),
60            ObsError::ResetVideoFailure(status) => write!(f, "Could not reset obs video. Status: {:?}", status),
61            ObsError::ResetVideoFailureGraphicsModule => write!(f, "Unable to reset video because the program attempted to change the graphics module. This is a bug!"),
62            ObsError::NullPointer => write!(f, "The function returned a null pointer, often indicating an error with creating the object of the requested pointer."),
63            ObsError::OutputAlreadyActive => write!(f, "Output is already active."),
64            ObsError::OutputStartFailure(s) => write!(f, "Output failed to start. Error is {:?}", s),
65            ObsError::OutputStopFailure(s) => write!(f, "Output failed to stop. Error is {:?}", s),
66            ObsError::OutputNotFound => write!(f, "Output not found."),
67            ObsError::DisplayCreationError(e) => write!(f, "Native error from the Windows API when creating a display: {:?}", e),
68            ObsError::OutputSaveBufferFailure(e) => write!(f, "Couldn't save output buffer: {:?}", e),
69            ObsError::SourceNotFound => write!(f, "Source not found."),
70            ObsError::BootstrapperFailure(error) => match error {
71                                ObsBootstrapError::GeneralError(e) => write!(f, "Bootstrapper error: {:?}", e),
72                                ObsBootstrapError::DownloadError(e) => write!(f, "Bootstrapper download error: {:?}", e),
73                                ObsBootstrapError::ExtractError(e) => write!(f, "Bootstrapper extract error: {:?}", e),
74                            },
75            ObsError::InvocationError(e) => write!(f, "The obs thread couldn't be called: {:?}", e),
76            ObsError::JsonParseError => write!(f, "Failed to parse JSON data."),
77            ObsError::NoSenderError => write!(f, "Couldn't get the sender of the signal."),
78        }
79    }
80}
81
82impl std::error::Error for ObsError {}