1use anyhow::anyhow;
2use std::fmt::{Debug, Formatter, Display};
3use std::str::Utf8Error;
4use docchi_archiver2::NouArcError;
5use std::error::Error;
6
7pub type CoreResult<T> = std::result::Result<T, CoreError>;
8
9
10
11pub struct CoreError {
12 e : anyhow::Error,
13}
14
15impl CoreError {
16 pub fn new(e : impl Error + Send + Sync + 'static) -> Self{ Self{ e : e.into() } }
17 pub fn to_string(&self) -> String{ self.e.to_string() }
18}
19
20impl Debug for CoreError {
21 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22 Debug::fmt(&self.e, f)
23 }
24}
25
26impl Display for CoreError {
27 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28 Display::fmt(&self.e, f)
29 }
30}
31
32impl Error for CoreError{
33 fn source(&self) -> Option<&(dyn Error + 'static)> {
34 self.e.source()
35 }
36}
37
38impl From<docchi_json5::MyError> for CoreError {
39 fn from(e : docchi_json5::MyError) -> Self {
40 Self{ e : e.into() }
41 }
42}
43
44impl From<std::io::Error> for CoreError {
45 fn from(e : std::io::Error) -> Self {
46 Self{ e : anyhow::Error::new(e) }
47 }
48}
49
50
51impl From<String> for CoreError {
52 fn from(s : String) -> Self {
53 Self{ e : anyhow!("{}", s) }
54 }
55}
56
57impl From<&str> for CoreError {
58 fn from(s : &str) -> Self {
59 Self{ e : anyhow!("{}", s) }
60 }
61}
62
63impl From<Utf8Error> for CoreError{
64 fn from(e : Utf8Error) -> Self{ Self::new(e) }
65}
66
67impl From<NouArcError> for CoreError{
68 fn from(e : NouArcError) -> Self{ Self::new(e) }
69}
70