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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::collections::TryReserveError;
use std::fmt::{Display, Formatter, Debug};
//use std::backtrace::Backtrace;

use anyhow::{anyhow};
use std::time::SystemTimeError;
use std::path::StripPrefixError;

/// The error type.
///
/// This wraps anyhow::Error. You can get it from Into trait.
///
/// Maybe the source error retrieved from anyhow::Error can be used to determine the cause of the error,
/// but currently, there's no guarantees about the error format.
///
/// I deeply depend on anyhow::Error::backtrace for debugging.
pub struct NouArcError{
    error : anyhow::Error,
}

impl NouArcError{
    pub(crate) fn new(e : impl Into<anyhow::Error>) -> Self{ Self{ error : e.into() } }
}

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

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

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


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

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

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

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


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

impl From<std::sync::mpsc::RecvError> for NouArcError{
    fn from(e : std::sync::mpsc::RecvError) -> Self { Self::new(e) }
}

impl<T> From<std::sync::mpsc::SendError<T>> for NouArcError{
    fn from(e : std::sync::mpsc::SendError<T>) -> Self { Self::new(anyhow!("{}", e)) }
}

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

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

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

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