Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

refactor - improved error

# This is the commit message #2:

refactor - removed dir argument
  • Loading branch information
rufevean committed Sep 12, 2024
1 parent 40909b4 commit ebd7199
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ impl Config {
file.read_to_string(&mut toml)?;
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,file_path : &Path) -> Result<Config, String> {
Self::from_toml_for_style_edition(toml,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 @@ -400,14 +402,24 @@ impl Config {
if !err.is_empty() {
eprint!("{err}");
}
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)
Ok(parsed_config.to_parsed_config(style_edition, edition, version, file_path.parent().unwrap()))
}
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 ebd7199

Please sign in to comment.