1use std::fmt::Display;
2
3use crate::enums::ObsResetVideoStatus;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub enum ObsError {
8 Failure,
10 MutexFailure,
13 ThreadFailure,
15 ResetVideoFailure(ObsResetVideoStatus),
17 ResetVideoFailureGraphicsModule,
20 ResetVideoFailureOutputActive,
22 NullPointer,
26 OutputAlreadyActive,
27 OutputStartFailure(Option<String>),
28 OutputStopFailure(Option<String>),
29 OutputPauseFailure(Option<String>),
30 OutputNotFound,
31 SourceNotFound,
32 SourceNotAvailable(String),
33 InvalidOperation(String),
34 StringConversionError,
36
37 DisplayCreationError(String),
39
40 OutputSaveBufferFailure(String),
41
42 InvocationError(String),
44
45 JsonParseError,
46 NoSenderError,
48 NoAvailableEncoders,
49 LockError(String),
51 Unexpected(String),
52
53 EncoderActive,
55
56 PlatformInitError(String),
58}
59
60#[cfg_attr(coverage_nightly, coverage(off))]
61impl Display for ObsError {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 write!(f, "OBS Error: ")?;
64
65 match self {
66 ObsError::Failure => write!(f, "`obs-startup` function failed on libobs"),
67 ObsError::MutexFailure => write!(f, "Failed to lock mutex describing whether there is a thread using libobs or not. Report to crate maintainer."),
68 ObsError::ThreadFailure => write!(f, "Some or no thread is already using libobs. This is a bug!"),
69 ObsError::ResetVideoFailure(status) => write!(f, "Could not reset obs video. Status: {:?}", status),
70 ObsError::ResetVideoFailureGraphicsModule => write!(f, "Unable to reset video because the program attempted to change the graphics module. This is a bug!"),
71 ObsError::ResetVideoFailureOutputActive => write!(f, "Unable to reset video because some outputs were still active."),
72 ObsError::NullPointer => write!(f, "The function returned a null pointer, often indicating an error with creating the object of the requested pointer."),
73 ObsError::OutputAlreadyActive => write!(f, "Output is already active."),
74 ObsError::OutputStartFailure(s) => write!(f, "Output failed to start. Error is {:?}", s),
75 ObsError::OutputStopFailure(s) => write!(f, "Output failed to stop. Error is {:?}", s),
76 ObsError::OutputNotFound => write!(f, "Output not found."),
77 ObsError::DisplayCreationError(e) => write!(f, "Native error from the Windows API when creating a display: {:?}", e),
78 ObsError::OutputSaveBufferFailure(e) => write!(f, "Couldn't save output buffer: {:?}", e),
79 ObsError::SourceNotFound => write!(f, "Source not found."),
80 ObsError::SourceNotAvailable(source_name) => write!(f, "Source {} is not available. See logs or similar to check why.", source_name),
81 ObsError::InvocationError(e) => write!(f, "The obs thread couldn't be called: {:?}", e),
82 ObsError::JsonParseError => write!(f, "Failed to parse JSON data."),
83 ObsError::NoSenderError => write!(f, "Couldn't get the sender of the signal."),
84 ObsError::NoAvailableEncoders => write!(f, "No available encoders found."),
85 ObsError::OutputPauseFailure(s) => write!(f, "Output failed to pause. Error is {:?}", s),
86 ObsError::LockError(e) => write!(f, "Error locking a mutex or RwLock: {:?}", e),
87 ObsError::Unexpected(e) => write!(f, "Unexpected error: {:?}", e),
88 ObsError::EncoderActive => write!(f, "Encoder is still active, stop the attached output before proceeding"),
89 ObsError::StringConversionError => write!(f, "Error converting a string between Rust and OBS"),
90 ObsError::PlatformInitError(e) => write!(f, "Error during platform-specific initialization: {}", e),
91 ObsError::InvalidOperation(e) => write!(f, "Invalid operation: {}", e),
92 }
93 }
94}
95
96impl std::error::Error for ObsError {}