Skip to main content

wayle_network/
error.rs

1use zbus::zvariant::OwnedObjectPath;
2
3/// Network service errors
4#[derive(thiserror::Error, Debug)]
5pub enum Error {
6    /// D-Bus communication error.
7    #[error("dbus operation failed: {0}")]
8    DbusError(#[from] zbus::Error),
9
10    /// Service initialization failed (used for top-level service startup).
11    #[error("cannot initialize network service: {0}")]
12    ServiceInitializationFailed(String),
13
14    /// Object not found at the specified D-Bus path.
15    #[error("object not found at path: {0}")]
16    ObjectNotFound(OwnedObjectPath),
17
18    /// Object exists but is of wrong type.
19    #[error("object at {object_path} is wrong type: expected {expected}, got {actual}")]
20    WrongObjectType {
21        /// DBus object path that has wrong type.
22        object_path: OwnedObjectPath,
23        /// Expected object type.
24        expected: String,
25        /// Actual object type found.
26        actual: String,
27    },
28
29    /// Cannot create or fetch an object.
30    #[error("cannot create {object_type} at {object_path}")]
31    ObjectCreationFailed {
32        /// Type of object that failed to create.
33        object_type: String,
34        /// DBus path where creation failed.
35        object_path: OwnedObjectPath,
36        /// Underlying error that caused the failure.
37        #[source]
38        source: Box<dyn std::error::Error + Send + Sync>,
39    },
40
41    /// Network operation failed.
42    #[error("cannot {operation}")]
43    OperationFailed {
44        /// The operation that failed.
45        operation: &'static str,
46        /// Underlying error that caused the failure.
47        #[source]
48        source: Box<dyn std::error::Error + Send + Sync>,
49    },
50
51    /// Monitoring requires a cancellation token.
52    #[error("cannot start monitoring: cancellation token not provided")]
53    MissingCancellationToken,
54
55    /// Data conversion or parsing failed.
56    #[error("cannot parse {data_type}: {reason}")]
57    DataConversionFailed {
58        /// Type of data that failed to convert.
59        data_type: String,
60        /// Reason for conversion failure.
61        reason: String,
62    },
63}