Skip to content

Commit

Permalink
refactor - improved error
Browse files Browse the repository at this point in the history
  • Loading branch information
rufevean committed Sep 1, 2024
1 parent 40909b4 commit d3f72b5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl Config {
Config::from_toml_for_style_edition(
&toml,
file_path.parent().unwrap(),
file_path,
edition,
style_edition,
version,
Expand Down Expand Up @@ -370,13 +371,14 @@ impl Config {
}

#[allow(dead_code)]
pub(super) fn from_toml(toml: &str, dir: &Path) -> Result<Config, String> {
Self::from_toml_for_style_edition(toml, dir, None, None, None)
pub(super) fn from_toml(toml: &str, dir: &Path,file_path : &Path) -> Result<Config, String> {
Self::from_toml_for_style_edition(toml, dir,file_path, None, None, None)
}

pub(crate) fn from_toml_for_style_edition(
toml: &str,
dir: &Path,
file_path: &Path,
edition: Option<Edition>,
style_edition: Option<StyleEdition>,
version: Option<Version>,
Expand All @@ -402,12 +404,22 @@ impl Config {
}
Ok(parsed_config.to_parsed_config(style_edition, edition, version, dir))
}
Err(e) => {
err.push_str("Error: Decoding config file failed:\n");
err.push_str(format!("{e}\n").as_str());
err.push_str("Please check your config file.");
Err(err)
}
Err(e) => {

let config_file_path_str = file_path.to_string_lossy();

let err_msg = format!(
"The file `{}` failed to parse.\n\
Error details: {}\n\
Help: Ensure that the configuration file at `{}` is correctly formatted.",
config_file_path_str,
e,
config_file_path_str
);

Err(err_msg)
}

}
}
}
Expand Down

0 comments on commit d3f72b5

Please sign in to comment.