1
1
use std:: path:: { Path , PathBuf } ;
2
2
3
+ use crate :: server:: ServerError ;
3
4
use crate :: ts:: error:: ApiError ;
4
5
5
6
use crate :: game:: error:: GameError ;
@@ -22,21 +23,18 @@ pub enum Error {
22
23
Api ( #[ from] ApiError ) ,
23
24
24
25
#[ error( "{0}" ) ]
25
- Io ( #[ from] IoError ) ,
26
-
27
- #[ error( "{0}" ) ]
28
- JsonParse ( #[ from] serde_json:: Error ) ,
26
+ Server ( #[ from] ServerError ) ,
29
27
30
28
#[ error( "{0}" ) ]
31
- TomlDeserialize ( #[ from] toml :: de :: Error ) ,
29
+ Io ( #[ from] IoError ) ,
32
30
33
31
#[ error( "{0}" ) ]
34
- TomlSerialize ( #[ from] toml :: ser :: Error ) ,
32
+ Parse ( #[ from] ParseError ) ,
35
33
}
36
34
37
35
#[ derive( Debug , thiserror:: Error ) ]
38
36
pub enum IoError {
39
- #[ error( "A file IO error occured : {0}." ) ]
37
+ #[ error( "A file IO error occurred : {0}." ) ]
40
38
Native ( std:: io:: Error , Option < PathBuf > ) ,
41
39
42
40
#[ error( "File not found: {0}." ) ]
@@ -64,6 +62,18 @@ pub enum IoError {
64
62
ZipError ( #[ from] zip:: result:: ZipError ) ,
65
63
}
66
64
65
+ #[ derive( Debug , thiserror:: Error ) ]
66
+ pub enum ParseError {
67
+ #[ error( "A json parse error occurred: {0}" ) ]
68
+ Json ( #[ from] serde_json:: Error ) ,
69
+
70
+ #[ error( "A toml serialization error occurred: {0}" ) ]
71
+ TomlSe ( #[ from] toml:: ser:: Error ) ,
72
+
73
+ #[ error( "A toml deserialization error occured: {0}" ) ]
74
+ TomlDe ( #[ from] toml:: de:: Error ) ,
75
+ }
76
+
67
77
impl From < std:: io:: Error > for Error {
68
78
fn from ( value : std:: io:: Error ) -> Self {
69
79
Self :: Io ( IoError :: Native ( value, None ) )
@@ -82,6 +92,23 @@ impl From<zip::result::ZipError> for Error {
82
92
}
83
93
}
84
94
95
+ impl From < serde_json:: Error > for Error {
96
+ fn from ( value : serde_json:: Error ) -> Self {
97
+ Self :: Parse ( ParseError :: Json ( value) )
98
+ }
99
+ }
100
+ impl From < toml:: de:: Error > for Error {
101
+ fn from ( value : toml:: de:: Error ) -> Self {
102
+ Self :: Parse ( ParseError :: TomlDe ( value) )
103
+ }
104
+ }
105
+
106
+ impl From < toml:: ser:: Error > for Error {
107
+ fn from ( value : toml:: ser:: Error ) -> Self {
108
+ Self :: Parse ( ParseError :: TomlSe ( value) )
109
+ }
110
+ }
111
+
85
112
pub trait IoResultToTcli < R > {
86
113
fn map_fs_error ( self , path : impl AsRef < Path > ) -> Result < R , IoError > ;
87
114
}
0 commit comments