Skip to content

Commit

Permalink
cli: improve filepath canonicalization error (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-schaaf committed Apr 7, 2022
1 parent ce88406 commit 248ef79
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,20 @@ impl _TestToml {
/// into a canonical one
fn canonicalize_filepath_from_origin(
file_path: impl AsRef<Path>,
path: impl AsRef<Path>,
origin: impl AsRef<Path>,
) -> Result<String> {
let previous_dir = std::env::current_dir()?;
std::env::set_current_dir(path.as_ref().parent().unwrap())?;
let result = fs::canonicalize(file_path)?.display().to_string();
std::env::set_current_dir(origin.as_ref().parent().unwrap())?;
let result = fs::canonicalize(&file_path)
.with_context(|| {
format!(
"Error reading (possibly relative) path: {}. If relative, this is the path that was used as the current path: {}",
&file_path.as_ref().display(),
&origin.as_ref().display()
)
})?
.display()
.to_string();
std::env::set_current_dir(previous_dir)?;
Ok(result)
}
Expand Down

0 comments on commit 248ef79

Please sign in to comment.