11use std:: path:: { Path , PathBuf } ;
22
3+ use crate :: server:: ServerError ;
34use crate :: ts:: error:: ApiError ;
45
56use crate :: game:: error:: GameError ;
@@ -22,21 +23,18 @@ pub enum Error {
2223 Api ( #[ from] ApiError ) ,
2324
2425 #[ error( "{0}" ) ]
25- Io ( #[ from] IoError ) ,
26-
27- #[ error( "{0}" ) ]
28- JsonParse ( #[ from] serde_json:: Error ) ,
26+ Server ( #[ from] ServerError ) ,
2927
3028 #[ error( "{0}" ) ]
31- TomlDeserialize ( #[ from] toml :: de :: Error ) ,
29+ Io ( #[ from] IoError ) ,
3230
3331 #[ error( "{0}" ) ]
34- TomlSerialize ( #[ from] toml :: ser :: Error ) ,
32+ Parse ( #[ from] ParseError ) ,
3533}
3634
3735#[ derive( Debug , thiserror:: Error ) ]
3836pub enum IoError {
39- #[ error( "A file IO error occured : {0}." ) ]
37+ #[ error( "A file IO error occurred : {0}." ) ]
4038 Native ( std:: io:: Error , Option < PathBuf > ) ,
4139
4240 #[ error( "File not found: {0}." ) ]
@@ -64,6 +62,18 @@ pub enum IoError {
6462 ZipError ( #[ from] zip:: result:: ZipError ) ,
6563}
6664
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+
6777impl From < std:: io:: Error > for Error {
6878 fn from ( value : std:: io:: Error ) -> Self {
6979 Self :: Io ( IoError :: Native ( value, None ) )
@@ -82,6 +92,23 @@ impl From<zip::result::ZipError> for Error {
8292 }
8393}
8494
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+
85112pub trait IoResultToTcli < R > {
86113 fn map_fs_error ( self , path : impl AsRef < Path > ) -> Result < R , IoError > ;
87114}
0 commit comments