summaryrefslogtreecommitdiffstats
path: root/src/error/error_type.rs
blob: 31ffa23c569b16aa3d696ead616d3347af4bed1b (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::convert::From;
use std::io;

use super::JoshutoErrorKind;

#[derive(Clone, Debug)]
pub struct JoshutoError {
    _kind: JoshutoErrorKind,
    _cause: String,
}

#[allow(dead_code)]
impl JoshutoError {
    pub fn new(_kind: JoshutoErrorKind, _cause: String) -> Self {
        Self { _kind, _cause }
    }

    pub fn kind(&self) -> &JoshutoErrorKind {
        &self._kind
    }
}

impl std::fmt::Display for JoshutoError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self._cause)
    }
}

impl From<io::Error> for JoshutoError {
    fn from(err: io::Error) -> Self {
        let cause = err.to_string();
        Self {
            _kind: JoshutoErrorKind::from(err.kind()),
            _cause: cause,
        }
    }
}

impl From<globset::Error> for JoshutoError {
    fn from(err: globset::Error) -> Self {
        let cause = err.to_string();
        Self {
            _kind: JoshutoErrorKind::from(err.kind()),
            _cause: cause,
        }
    }
}

impl From<std::env::VarError> for JoshutoError {
    fn from(err: std::env::VarError) -> Self {
        let cause = err.to_string();
        Self {
            _kind: JoshutoErrorKind::from(err),
            _cause: cause,
        }
    }
}

impl From<trash::Error> for JoshutoError {
    fn from(err: trash::Error) -> Self {
        let cause = err.to_string();
        Self {
            _kind: JoshutoErrorKind::TrashError,
            _cause: cause,
        }
    }
}

impl From<toml::de::Error> for JoshutoError {
    fn from(err: toml::de::Error) -> Self {
        let cause = err.to_string();
        Self {
            _kind: JoshutoErrorKind::from(err),
            _cause: cause,
        }
    }
}