waycap_rs/types/
error.rs

1use std::error::Error;
2use std::fmt;
3use std::io;
4
5#[derive(Debug)]
6pub enum WaycapError {
7    /// Errors from FFmpeg
8    FFmpeg(ffmpeg_next::Error),
9    /// Egl Errors,
10    Egl(khronos_egl::Error),
11    /// Errors from PipeWire
12    PipeWire(String),
13    /// Errors from XDG Portal
14    Portal(String),
15    /// I/O errors
16    Io(io::Error),
17    /// Initialization errors
18    Init(String),
19    /// Configuration errors
20    Config(String),
21    /// Stream errors
22    Stream(String),
23    /// Encoding errors
24    Encoding(String),
25    /// Device errors
26    Device(String),
27    /// Validation errors
28    Validation(String),
29    /// Other errors
30    Other(String),
31}
32
33impl fmt::Display for WaycapError {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            WaycapError::FFmpeg(err) => write!(f, "FFmpeg error: {err}"),
37            WaycapError::PipeWire(msg) => write!(f, "PipeWire error: {msg}"),
38            WaycapError::Portal(msg) => write!(f, "XDG Portal error: {msg}"),
39            WaycapError::Io(err) => write!(f, "I/O error: {err}"),
40            WaycapError::Init(msg) => write!(f, "Initialization error: {msg}"),
41            WaycapError::Config(msg) => write!(f, "Configuration error: {msg}"),
42            WaycapError::Stream(msg) => write!(f, "Stream error: {msg}"),
43            WaycapError::Encoding(msg) => write!(f, "Encoding error: {msg}"),
44            WaycapError::Device(msg) => write!(f, "Device error: {msg}"),
45            WaycapError::Validation(msg) => write!(f, "Validation error: {msg}"),
46            WaycapError::Other(msg) => write!(f, "Error: {msg}"),
47            WaycapError::Egl(msg) => write!(f, "Egl Error: {msg}"),
48        }
49    }
50}
51
52impl Error for WaycapError {
53    fn source(&self) -> Option<&(dyn Error + 'static)> {
54        match self {
55            WaycapError::FFmpeg(err) => Some(err),
56            WaycapError::Io(err) => Some(err),
57            _ => None,
58        }
59    }
60}
61
62impl From<ffmpeg_next::Error> for WaycapError {
63    fn from(err: ffmpeg_next::Error) -> Self {
64        WaycapError::FFmpeg(err)
65    }
66}
67
68impl From<io::Error> for WaycapError {
69    fn from(err: io::Error) -> Self {
70        WaycapError::Io(err)
71    }
72}
73
74impl From<pipewire::Error> for WaycapError {
75    fn from(err: pipewire::Error) -> Self {
76        WaycapError::PipeWire(err.to_string())
77    }
78}
79
80impl From<portal_screencast_waycap::PortalError> for WaycapError {
81    fn from(err: portal_screencast_waycap::PortalError) -> Self {
82        WaycapError::Portal(err.to_string())
83    }
84}
85
86impl From<String> for WaycapError {
87    fn from(err: String) -> Self {
88        WaycapError::Other(err)
89    }
90}
91
92impl From<&str> for WaycapError {
93    fn from(err: &str) -> Self {
94        WaycapError::Other(err.to_string())
95    }
96}
97
98impl From<khronos_egl::Error> for WaycapError {
99    fn from(err: khronos_egl::Error) -> Self {
100        WaycapError::Egl(err)
101    }
102}
103
104pub type Result<T> = std::result::Result<T, WaycapError>;