summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 09e6e86df54685b65bd40accce33420687f23ddd (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
use std::io;
use std::sync::Arc;

use thiserror::Error;

#[derive(Debug, Clone, Error)]
#[error(transparent)]
pub enum Error {
    IO(Arc<io::Error>),
    #[error("config does not exist")]
    ConfigMissing,
    #[error("JSON parsing error: {0}")]
    SerdeJSON(Arc<serde_json::Error>),
    #[error("TOML parsing error: {0}")]
    SerdeTOML(#[from] toml::de::Error),
    RustFmt(Arc<rust_format::Error>),
    #[error("the element tree contains no matching element")]
    NonExistentElement,
    #[error(
        "the file dialog has been closed without selecting a valid option"
    )]
    DialogClosed,
    #[error("{0}")]
    Other(String),
}

impl From<io::Error> for Error {
    fn from(value: io::Error) -> Self {
        Self::IO(Arc::new(value))
    }
}

impl From<serde_json::Error> for Error {
    fn from(value: serde_json::Error) -> Self {
        Self::SerdeJSON(Arc::new(value))
    }
}

impl From<rust_format::Error> for Error {
    fn from(value: rust_format::Error) -> Self {
        Self::RustFmt(Arc::new(value))
    }
}

impl From<&str> for Error {
    fn from(value: &str) -> Self {
        Self::Other(value.to_owned())
    }
}

impl From<String> for Error {
    fn from(value: String) -> Self {
        Self::Other(value)
    }
}

impl From<Error> for String {
    fn from(value: Error) -> Self {
        value.to_string()
    }
}