pulsectl/controllers/
error.rs

1use crate::error::Error;
2
3/// Error thrown while fetching data from pulseaudio.
4#[derive(Debug, Clone)]
5pub enum ControllerError {
6    /// When PulseAudio returns an error code
7    PulseCtl(String),
8    /// When a request for data fails for whatever reason
9    GetInfo(String),
10}
11
12impl std::fmt::Display for ControllerError {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            Self::PulseCtl(e) => f.write_str(&format!("PulseCtl error: {}", e)),
16            Self::GetInfo(e) => f.write_str(&format!("GetInfo error: {}", e)),
17        }
18    }
19}
20
21impl std::error::Error for ControllerError {}
22
23impl From<Error> for ControllerError {
24    fn from(error: Error) -> Self {
25        Self::PulseCtl(error.to_string())
26    }
27}