Skip to main content

wayle_bluetooth/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub(crate) struct ResponderDropped;
5
6impl fmt::Display for ResponderDropped {
7    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8        write!(f, "pairing responder receiver was dropped")
9    }
10}
11
12impl std::error::Error for ResponderDropped {}
13
14/// Bluetooth service errors.
15#[derive(thiserror::Error, Debug)]
16pub enum Error {
17    /// D-Bus communication error.
18    #[error("dbus error: {0}")]
19    Dbus(#[from] zbus::Error),
20
21    /// Service initialization failed.
22    #[error("cannot initialize bluetooth service")]
23    ServiceInitialization(#[source] Box<dyn std::error::Error + Send + Sync>),
24
25    /// Agent registration failed.
26    #[error("cannot register bluetooth agent")]
27    AgentRegistration(#[source] Box<dyn std::error::Error + Send + Sync>),
28
29    /// Adapter operation failed.
30    #[error("cannot {operation} on adapter")]
31    AdapterOperation {
32        /// The operation that failed.
33        operation: &'static str,
34        /// The underlying D-Bus error.
35        #[source]
36        source: zbus::Error,
37    },
38
39    /// No primary adapter available for the requested operation.
40    #[error("cannot {operation}: no primary adapter available")]
41    NoPrimaryAdapter {
42        /// The operation that requires an adapter.
43        operation: &'static str,
44    },
45
46    /// Object discovery failed.
47    #[error("cannot discover bluetooth objects")]
48    Discovery(#[source] zbus::fdo::Error),
49
50    /// Monitoring requires a cancellation token but none was provided.
51    #[error("cannot start monitoring: no cancellation token configured")]
52    NoCancellationToken,
53
54    /// Pairing request type mismatch.
55    #[error("cannot provide {request_type}: no {request_type} request is pending")]
56    NoPendingRequest {
57        /// The type of pairing request expected.
58        request_type: &'static str,
59    },
60
61    /// Pairing responder unavailable.
62    #[error("cannot provide {request_type}: no responder available")]
63    NoResponder {
64        /// The type of responder expected.
65        request_type: &'static str,
66    },
67
68    /// Pairing response channel send failed.
69    #[error("cannot send {request_type} response")]
70    ResponderSend {
71        /// The type of response being sent.
72        request_type: &'static str,
73        /// The underlying send error.
74        #[source]
75        source: Box<dyn std::error::Error + Send + Sync>,
76    },
77}