aboutsummaryrefslogtreecommitdiff
path: root/core/src/error.rs
blob: 15947c87eabee5477b2bfc21a3759ba39f00a194 (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
use thiserror::Error as ThisError;

pub type Result<T> = std::result::Result<T, Error>;

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

    #[error("Timeout Error")]
    Timeout,

    #[error("Path Not Found Error: {0}")]
    PathNotFound(&'static str),

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

    #[error("Channel Receive Error: {0}")]
    ChannelRecv(String),

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

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

impl<T> From<smol::channel::SendError<T>> for Error {
    fn from(error: smol::channel::SendError<T>) -> Self {
        Error::ChannelSend(error.to_string())
    }
}

impl From<smol::channel::RecvError> for Error {
    fn from(error: smol::channel::RecvError) -> Self {
        Error::ChannelRecv(error.to_string())
    }
}

impl From<bincode::error::DecodeError> for Error {
    fn from(error: bincode::error::DecodeError) -> Self {
        Error::Decode(error.to_string())
    }
}

impl From<bincode::error::EncodeError> for Error {
    fn from(error: bincode::error::EncodeError) -> Self {
        Error::Encode(error.to_string())
    }
}