summaryrefslogtreecommitdiffstats
path: root/src/error.rs
blob: 834b7cf680e804b98f7992126ec333e5c5f9ed39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("IO error: {0}")]
    IO(#[from] std::io::Error),

    #[error("Poison error: {0}")]
    Poison(String),

    #[error("Join error: {0}")]
    Join(#[from] tokio::task::JoinError),

    #[error("Bincode error: {0}")]
    Bincode(#[from] bincode::Error),

    #[error("ZBus error: {0}")]
    ZBus(#[from] zbus::Error),

    #[error("ZBus fdo error: {0}")]
    Fdo(#[from] zbus::fdo::Error),

    #[error("ZBus zvariant error: {0}")]
    ZVariant(#[from] zbus::zvariant::Error),

    #[error("Json serde error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("Invalid color format: {0}")]
    Color(String),

    #[error("Invalid playback state")]
    PlaybackState,

    #[error("Invalid volume value")]
    Volume,

    #[error("Send error: {0}")]
    Send(String),

    #[error("Invalid instance value")]
    Instance,

    #[error("Failed to get player, channel closed")]
    Channel,
}

impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
    fn from(err: tokio::sync::mpsc::error::SendError<T>) -> Self {
        Self::Send(err.to_string())
    }
}

impl<T> From<std::sync::PoisonError<T>> for Error {
    fn from(err: std::sync::PoisonError<T>) -> Self {
        Self::Poison(err.to_string())
    }
}