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
use anyhow::anyhow;
use std::fmt::{Debug, Formatter, Display};
use std::str::Utf8Error;
use dochy_archiver2::NouArcError;

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



pub struct CoreError {
    e : anyhow::Error,
}

impl CoreError {
    pub fn new(e : impl Into<anyhow::Error>) -> Self{ Self{ e : e.into() } }
    pub fn to_string(&self) -> String{ self.e.to_string() }
}

impl Debug for CoreError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Debug::fmt(&self.e, f)
    }
}

impl Display for CoreError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        Display::fmt(&self.e, f)
    }
}

impl From<dochy_json5::MyError> for CoreError {
    fn from(e : dochy_json5::MyError) -> Self {
        Self{ e : e.into() }
    }
}

impl From<std::io::Error> for CoreError {
    fn from(e : std::io::Error) -> Self {
        Self{ e : anyhow::Error::new(e) }
    }
}


impl From<String> for CoreError {
    fn from(s : String) -> Self {
        Self{ e : anyhow!("{}", s) }
    }
}

impl From<&str> for CoreError {
    fn from(s : &str) -> Self {
        Self{ e : anyhow!("{}", s) }
    }
}

impl From<Utf8Error> for CoreError{
    fn from(e : Utf8Error) -> Self{ Self::new(e) }
}

impl From<NouArcError> for CoreError{
    fn from(e : NouArcError) -> Self{ Self::new(e) }
}

impl Into<anyhow::Error> for CoreError {
    fn into(self) -> anyhow::Error {
        self.e
    }
}