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