@@ -6,7 +6,6 @@ use std::fmt;
6
6
use std:: result;
7
7
use std:: path:: PathBuf ;
8
8
9
- use toml:: Parser ;
10
9
use chemfiles;
11
10
12
11
use lumol:: units:: ParseError ;
@@ -19,7 +18,7 @@ pub type Result<T> = result::Result<T, Error>;
19
18
#[ derive( Debug ) ]
20
19
pub enum Error {
21
20
/// Error in the TOML input file
22
- TOML ( String ) ,
21
+ TOML ( Box < error :: Error > ) ,
23
22
/// IO error, and associated file path
24
23
Io ( io:: Error , PathBuf ) ,
25
24
/// Error while reading a trajectory file
@@ -63,31 +62,34 @@ impl From<ParseError> for Error {
63
62
impl fmt:: Display for Error {
64
63
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> result:: Result < ( ) , fmt:: Error > {
65
64
use std:: error:: Error as StdError ;
66
- let message = match * self {
65
+ match * self {
67
66
Error :: Io ( ref err, ref path) => {
68
67
match err. kind ( ) {
69
68
io:: ErrorKind :: NotFound => {
70
- format ! ( "can not find '{}'" , path. display( ) )
69
+ try! ( write ! ( fmt , "can not find '{}'" , path. display( ) ) )
71
70
}
72
71
io:: ErrorKind :: PermissionDenied => {
73
- format ! ( "permission to access '{}' denied" , path. display( ) )
72
+ try! ( write ! ( fmt , "permission to access '{}' denied" , path. display( ) ) )
74
73
}
75
74
_ => {
76
- format ! ( "error with '{}': {}" , path. display( ) , self . description( ) )
75
+ try! ( write ! ( fmt , "error with '{}': {}" , path. display( ) , self . description( ) ) )
77
76
}
78
77
}
79
78
}
80
- _ => String :: from ( self . description ( ) )
79
+ Error :: Trajectory ( ref err) => try!( write ! ( fmt, "{}" , err) ) ,
80
+ Error :: TOML ( ref err) => try!( write ! ( fmt, "{}" , err) ) ,
81
+ Error :: Config ( ref err) => try!( write ! ( fmt, "{}" , err) ) ,
82
+ Error :: Unit ( ref err) => try!( write ! ( fmt, "{}" , err) ) ,
81
83
} ;
82
- try!( write ! ( fmt, "{}" , message) ) ;
83
84
Ok ( ( ) )
84
85
}
85
86
}
86
87
87
88
impl error:: Error for Error {
88
89
fn description ( & self ) -> & str {
89
90
match * self {
90
- Error :: TOML ( ref err) | Error :: Config ( ref err) => err,
91
+ Error :: Config ( ref err) => err,
92
+ Error :: TOML ( ref err) => err. description ( ) ,
91
93
Error :: Io ( ref err, _) => err. description ( ) ,
92
94
Error :: Trajectory ( ref err) => err. description ( ) ,
93
95
Error :: Unit ( ref err) => err. description ( ) ,
@@ -103,13 +105,3 @@ impl error::Error for Error {
103
105
}
104
106
}
105
107
}
106
-
107
- pub fn toml_error_to_string ( parser : & Parser ) -> String {
108
- let errors = parser. errors . iter ( ) . map ( |error|{
109
- let ( line, _) = parser. to_linecol ( error. lo ) ;
110
- format ! ( "{} at line {}" , error. desc, line + 1 )
111
- } ) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ;
112
-
113
- let plural = if errors. len ( ) == 1 { "" } else { "s" } ;
114
- return format ! ( "TOML parsing error{}: {}" , plural, errors) ;
115
- }
0 commit comments