1use pulse::error::PAErr;
2
3use crate::controllers::error::ControllerError;
4
5#[derive(Debug, Clone)]
7pub enum Error {
8 Connect(String),
10 Operation(String),
12 PulseAudio(String),
14 Controller(ControllerError),
16}
17
18impl std::error::Error for Error {}
19
20impl std::fmt::Display for Error {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 match self {
23 Self::Connect(e) => f.write_str(&format!("ConnectError: {}", e)),
24 Self::Operation(e) => f.write_str(&format!("OperationError: {}", e)),
25 Self::PulseAudio(e) => f.write_str(&format!("PulseAudioError: {}", e)),
26 Self::Controller(e) => f.write_str(&format!("ControllerError: {}", e)),
27 }
28 }
29}
30
31impl From<PAErr> for Error {
32 fn from(error: PAErr) -> Self {
33 Self::PulseAudio(
34 error
35 .to_string()
36 .unwrap_or_else(|| "Unknown error".to_string()),
37 )
38 }
39}