notifications/error.rs
1use thiserror::Error;
2
3/// Enum representing possible errors to happen during the usage of [`crate::NotificationService`].
4#[derive(Error, Debug)]
5pub enum Error {
6 /// D-Bus error. Carries [`zbus::Error`] inside.
7 ///
8 /// Usually returned if another notification daemon is running on the session bus.
9 #[error("D-Bus error: {0}")]
10 DBusError(#[from] zbus::Error),
11
12 /// Returned if attempted to call methods that involve D-Bus interaction and have not called
13 /// [`crate::NotificationService::run`] yet.
14 #[error("Connection not exist error")]
15 NoConnection,
16
17 /// Returned in case of I/O file errors. Carries [`std::io::Error`].
18 #[error("I/O Error: {0}")]
19 IOError(#[from] std::io::Error),
20
21 /// Returned if JSON parsing of the notification history failed. Carries [`serde_json::Error`].
22 ///
23 /// Usually indicates that the JSON markup is corrupted.
24 #[error(
25 "JSON error (you may need to manually fix or remove history file at ~/.cache/ignis_notifications/notifications.json): {0}"
26 )]
27 JSONError(#[from] serde_json::Error),
28
29 /// Returned if the notification with the given ID is not found.
30 #[error("No notification found with id: {0}")]
31 NotificationNotFound(u32),
32
33 /// Returned if [`crate::NotificationService::run`] is called more than once.
34 #[error("Attempted to initialize connection twice (run() was called twice)")]
35 ConnectionInitializedTwice,
36}
37
38/// Alias for a [`std::result::Result`] with the error type [`crate::Error`].
39pub type Result<T> = std::result::Result<T, Error>;