Skip to main content

wayle_audio/
error.rs

1use libpulse_binding::context::State as ContextState;
2
3use super::types::{device::DeviceType, stream::StreamType};
4
5/// Required component that was missing when attempting to start monitoring.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum MissingMonitoringComponent {
8    /// Cancellation token was not provided.
9    CancellationToken,
10    /// Event sender was not provided.
11    EventSender,
12}
13
14impl std::fmt::Display for MissingMonitoringComponent {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            Self::CancellationToken => write!(f, "cancellation token"),
18            Self::EventSender => write!(f, "event sender"),
19        }
20    }
21}
22
23/// PulseAudio service errors.
24#[derive(thiserror::Error, Debug)]
25pub enum Error {
26    /// Cannot create PulseAudio context.
27    #[error("cannot create pulseaudio context")]
28    ContextCreationFailed,
29
30    /// Cannot connect to PulseAudio server.
31    #[error("cannot connect to pulseaudio server")]
32    ConnectionFailed(#[source] libpulse_binding::error::PAErr),
33
34    /// PulseAudio context entered a failed state.
35    #[error("pulseaudio context entered failed state: {0:?}")]
36    ContextStateFailed(ContextState),
37
38    /// Device not found.
39    #[error("device {index:?} ({device_type:?}) not found")]
40    DeviceNotFound {
41        /// Device index that was not found.
42        index: u32,
43        /// Type of device (input/output).
44        device_type: DeviceType,
45    },
46
47    /// Stream not found.
48    #[error("stream {index:?} ({stream_type:?}) not found")]
49    StreamNotFound {
50        /// Stream index that was not found.
51        index: u32,
52        /// Type of stream.
53        stream_type: StreamType,
54    },
55
56    /// Command channel disconnected.
57    #[error("command channel disconnected")]
58    CommandChannelDisconnected,
59
60    /// Lock poisoned due to panic in another thread.
61    #[error("shared data lock poisoned")]
62    LockPoisoned,
63
64    /// Monitoring cannot start because a required component was not provided.
65    #[error("cannot start monitoring: {0} not available")]
66    MonitoringNotInitialized(MissingMonitoringComponent),
67
68    /// Cannot connect to D-Bus session bus.
69    #[error("cannot connect to dbus session bus")]
70    DbusConnectionFailed(#[source] zbus::Error),
71
72    /// Cannot register D-Bus object.
73    #[error("cannot register dbus object at {path}")]
74    DbusObjectRegistrationFailed {
75        /// The D-Bus path where registration was attempted.
76        path: &'static str,
77        /// The underlying zbus error.
78        #[source]
79        source: zbus::Error,
80    },
81
82    /// Cannot acquire D-Bus service name.
83    #[error("cannot acquire dbus name {name}")]
84    DbusNameAcquisitionFailed {
85        /// The D-Bus name that could not be acquired.
86        name: &'static str,
87        /// The underlying zbus error.
88        #[source]
89        source: zbus::Error,
90    },
91}