libobs_window_helper/
error.rs1use std::fmt::Display;
2
3#[derive(Clone, Debug, PartialEq, Eq)]
5pub enum WindowHelperError {
6 WindowsApiError(String),
8 FileNameError,
10 StringConversionError,
12 MicrosoftInternalExe,
14 ObsExe,
16 InvalidState(String),
18 NoWindowFound,
20 IntConversionError(String),
22}
23
24impl Display for WindowHelperError {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 match self {
27 WindowHelperError::WindowsApiError(e) => write!(f, "Windows API error: {}", e),
28 WindowHelperError::FileNameError => write!(f, "Failed to get file name"),
29 WindowHelperError::StringConversionError => write!(f, "Failed to convert to string"),
30 WindowHelperError::MicrosoftInternalExe => {
31 write!(f, "Handle is a Microsoft internal exe")
32 }
33 WindowHelperError::ObsExe => write!(f, "Handle is obs64.exe"),
34 WindowHelperError::InvalidState(msg) => write!(f, "Invalid state: {}", msg),
35 WindowHelperError::NoWindowFound => write!(f, "No window found"),
36 WindowHelperError::IntConversionError(e) => {
37 write!(f, "Integer conversion error: {}", e)
38 }
39 }
40 }
41}
42
43impl std::error::Error for WindowHelperError {}
44
45#[cfg(windows)]
46impl From<windows::core::Error> for WindowHelperError {
47 fn from(err: windows::core::Error) -> Self {
48 WindowHelperError::WindowsApiError(err.to_string())
49 }
50}
51
52impl From<std::num::TryFromIntError> for WindowHelperError {
53 fn from(err: std::num::TryFromIntError) -> Self {
54 WindowHelperError::IntConversionError(err.to_string())
55 }
56}
57
58impl From<std::convert::Infallible> for WindowHelperError {
59 fn from(_: std::convert::Infallible) -> Self {
60 unreachable!()
62 }
63}