1use std::fmt::Display;
2
3use crate::enums::ObsResetVideoStatus;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub enum ObsError {
8 Failure,
10 InvalidDll,
12 MutexFailure,
15 ThreadFailure,
17 ResetVideoFailure(ObsResetVideoStatus),
19 ResetVideoFailureGraphicsModule,
22 ResetVideoFailureOutputActive,
24 NullPointer(Option<String>),
28 OutputAlreadyActive,
29 OutputStartFailure(Option<String>),
30 OutputStopFailure(Option<String>),
31 OutputPauseFailure(Option<String>),
32 OutputNotFound,
33 SourceNotFound,
34 SourceNotAvailable(String),
35 InvalidOperation(String),
36 StringConversionError,
38
39 DisplayCreationError(String),
41
42 OutputSaveBufferFailure(String),
43
44 InvocationError(String),
46
47 JsonParseError,
48 NoSenderError,
50 NoAvailableEncoders,
51 LockError(String),
53 Unexpected(String),
54
55 EncoderActive,
57
58 PlatformInitError(String),
60
61 IoError(String),
63
64 SignalDataError(String),
66
67 EnumConversionError(String),
69
70 RuntimeChannelError(String),
72
73 RuntimeOutsideThread,
77
78 FilterAlreadyApplied,
80}
81
82#[cfg_attr(coverage_nightly, coverage(off))]
83impl Display for ObsError {
84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 write!(f, "OBS Error: ")?;
86
87 match self {
88 ObsError::Failure => write!(f, "`obs-startup` function failed on libobs"),
89 ObsError::MutexFailure => write!(f, "Failed to lock mutex describing whether there is a thread using libobs or not. Report to crate maintainer."),
90 ObsError::ThreadFailure => write!(f, "Some or no thread is already using libobs. This is a bug!"),
91 ObsError::ResetVideoFailure(status) => write!(f, "Could not reset obs video. Status: {:?}", status),
92 ObsError::ResetVideoFailureGraphicsModule => write!(f, "Unable to reset video because the program attempted to change the graphics module. This is a bug!"),
93 ObsError::ResetVideoFailureOutputActive => write!(f, "Unable to reset video because some outputs were still active."),
94 ObsError::NullPointer(e) => write!(f, "The function returned a null pointer, often indicating an error with creating the object of the requested pointer. Details: {:?}", e),
95 ObsError::OutputAlreadyActive => write!(f, "Output is already active."),
96 ObsError::OutputStartFailure(s) => write!(f, "Output failed to start. Error is {:?}", s),
97 ObsError::OutputStopFailure(s) => write!(f, "Output failed to stop. Error is {:?}", s),
98 ObsError::OutputNotFound => write!(f, "Output not found."),
99 ObsError::DisplayCreationError(e) => write!(f, "Native error from the Windows API when creating a display: {:?}", e),
100 ObsError::OutputSaveBufferFailure(e) => write!(f, "Couldn't save output buffer: {:?}", e),
101 ObsError::SourceNotFound => write!(f, "Source not found."),
102 ObsError::SourceNotAvailable(source_name) => write!(f, "Source {} is not available. See logs or similar to check why.", source_name),
103 ObsError::InvocationError(e) => write!(f, "The obs thread couldn't be called: {:?}", e),
104 ObsError::JsonParseError => write!(f, "Failed to parse JSON data."),
105 ObsError::NoSenderError => write!(f, "Couldn't get the sender of the signal."),
106 ObsError::NoAvailableEncoders => write!(f, "No available encoders found."),
107 ObsError::OutputPauseFailure(s) => write!(f, "Output failed to pause. Error is {:?}", s),
108 ObsError::LockError(e) => write!(f, "Error locking a mutex or RwLock: {:?}. You should probably restart the application to avoid memory leaks.", e),
109 ObsError::Unexpected(e) => write!(f, "Unexpected error: {:?}", e),
110 ObsError::EncoderActive => write!(f, "Encoder is still active, stop the attached output before proceeding"),
111 ObsError::StringConversionError => write!(f, "Error converting a string between Rust and OBS"),
112 ObsError::PlatformInitError(e) => write!(f, "Error during platform-specific initialization: {}", e),
113 ObsError::InvalidOperation(e) => write!(f, "Invalid operation: {}", e),
114 ObsError::IoError(e) => write!(f, "I/O error: {}", e),
115 ObsError::SignalDataError(e) => write!(f, "Signal data error: {}", e),
116 ObsError::EnumConversionError(e) => write!(f, "Enum conversion error: {}", e),
117 ObsError::RuntimeChannelError(e) => write!(f, "Runtime channel error: {}", e),
118 ObsError::InvalidDll => write!(f, "A dummy DLL was loaded instead of the real libobs DLL. Make sure you bootstrap properly with libobs-bootstrapper"),
119 #[cfg(feature="enable_runtime")]
120 ObsError::RuntimeOutsideThread => write!(f, "Attempted to call a OBS runtime function from outside the OBS thread. This is a bug in the crate!"),
121 #[cfg(not(feature="enable_runtime"))]
122 ObsError::RuntimeOutsideThread => write!(f, "Attempted to call a OBS runtime function from outside the OBS thread. Make sure that you do not use any OBS struct from a different thread than the one where the ObsContext was initialized. THIS BUG WILL CAUSE MEMORY CORRUPTION OR DEADLOCKS!"),
123 ObsError::FilterAlreadyApplied => write!(f, "Filter was applied already."),
124 }
125 }
126}
127
128impl std::error::Error for ObsError {}