bitwarden_ipc/
error.rs

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
use thiserror::Error;

#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum SendError<Crypto, Com> {
    #[error("Crypto error: {0}")]
    Crypto(Crypto),

    #[error("Communication error: {0}")]
    Communication(Com),
}

#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum ReceiveError<Crypto, Com> {
    #[error("The receive operation timed out")]
    Timeout,

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

    #[error("Communication error: {0}")]
    Communication(Com),
}

#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum TypedReceiveError<Typing, Crypto, Com> {
    #[error("Typing error: {0}")]
    Typing(Typing),

    #[error("The receive operation timed out")]
    Timeout,

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

    #[error("Communication error: {0}")]
    Communication(Com),
}

impl<Typing, Crypto, Com> From<ReceiveError<Crypto, Com>>
    for TypedReceiveError<Typing, Crypto, Com>
{
    fn from(value: ReceiveError<Crypto, Com>) -> Self {
        match value {
            ReceiveError::Timeout => TypedReceiveError::Timeout,
            ReceiveError::Crypto(crypto) => TypedReceiveError::Crypto(crypto),
            ReceiveError::Communication(com) => TypedReceiveError::Communication(com),
        }
    }
}