@@ -132,13 +132,27 @@ impl WaypointConfig {
132
132
pub fn waypoint ( & self ) -> Waypoint {
133
133
let waypoint = match & self {
134
134
WaypointConfig :: FromConfig ( waypoint) => Some ( * waypoint) ,
135
- WaypointConfig :: FromFile ( path) => {
136
- let content = fs:: read_to_string ( path)
137
- . unwrap_or_else ( |_| panic ! ( "Failed to read waypoint file {}" , path. display( ) ) ) ;
138
- Some (
139
- Waypoint :: from_str ( content. trim ( ) )
140
- . unwrap_or_else ( |_| panic ! ( "Failed to parse waypoint: {}" , content. trim( ) ) ) ,
141
- )
135
+ WaypointConfig :: FromFile ( waypoint_path) => {
136
+ if !waypoint_path. exists ( ) {
137
+ panic ! (
138
+ "Waypoint file not found! Ensure the given path is correct: {:?}" ,
139
+ waypoint_path. display( )
140
+ ) ;
141
+ }
142
+ let content = fs:: read_to_string ( waypoint_path) . unwrap_or_else ( |error| {
143
+ panic ! (
144
+ "Failed to read waypoint file {:?}. Error: {:?}" ,
145
+ waypoint_path. display( ) ,
146
+ error
147
+ )
148
+ } ) ;
149
+ Some ( Waypoint :: from_str ( content. trim ( ) ) . unwrap_or_else ( |error| {
150
+ panic ! (
151
+ "Failed to parse waypoint: {:?}. Error: {:?}" ,
152
+ content. trim( ) ,
153
+ error
154
+ )
155
+ } ) )
142
156
}
143
157
WaypointConfig :: FromStorage ( backend) => {
144
158
let storage: Storage = backend. into ( ) ;
@@ -255,8 +269,8 @@ impl NodeConfig {
255
269
}
256
270
257
271
/// Reads the config file and returns the configuration object in addition to doing some
258
- /// post-processing of the config
259
- /// Paths used in the config are either absolute or relative to the config location
272
+ /// post-processing of the config.
273
+ /// Paths used in the config are either absolute or relative to the config location.
260
274
pub fn load < P : AsRef < Path > > ( input_path : P ) -> Result < Self , Error > {
261
275
let mut config = Self :: load_config ( & input_path) ?;
262
276
@@ -420,11 +434,23 @@ impl NodeConfig {
420
434
421
435
pub trait PersistableConfig : Serialize + DeserializeOwned {
422
436
fn load_config < P : AsRef < Path > > ( path : P ) -> Result < Self , Error > {
423
- let mut file = File :: open ( & path)
424
- . map_err ( |e| Error :: IO ( path. as_ref ( ) . to_str ( ) . unwrap ( ) . to_string ( ) , e) ) ?;
437
+ // Open the file and read it into a string
438
+ let config_path_string = path. as_ref ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
439
+ let mut file = File :: open ( & path) . map_err ( |error| {
440
+ Error :: Unexpected ( format ! (
441
+ "Failed to open config file: {:?}. Error: {:?}" ,
442
+ config_path_string, error
443
+ ) )
444
+ } ) ?;
425
445
let mut contents = String :: new ( ) ;
426
- file. read_to_string ( & mut contents)
427
- . map_err ( |e| Error :: IO ( path. as_ref ( ) . to_str ( ) . unwrap ( ) . to_string ( ) , e) ) ?;
446
+ file. read_to_string ( & mut contents) . map_err ( |error| {
447
+ Error :: Unexpected ( format ! (
448
+ "Failed to read the config file into a string: {:?}. Error: {:?}" ,
449
+ config_path_string, error
450
+ ) )
451
+ } ) ?;
452
+
453
+ // Parse the file string
428
454
Self :: parse ( & contents)
429
455
}
430
456
0 commit comments