Skip to content

Commit

Permalink
Rewrite the ambiguous path error function for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jul 18, 2022
1 parent 457757b commit 6e74ae9
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,21 @@ fn ambiguous_path_error(
metadata: &cargo_metadata::Metadata,
dir: &Path,
) -> Error {
let possible_paths = metadata
.workspace_members
.iter()
.map(|id| PathBuf::from(&metadata[id].manifest_path))
.map(|mut cargo_toml_path| {
let _ = cargo_toml_path.pop();
cargo_toml_path
})
.map(|crate_dir| {
crate_dir
.strip_prefix(&metadata.workspace_root)
.unwrap_or(&crate_dir)
.to_path_buf()
})
.collect();
let mut possible_paths = Vec::new();

for id in &metadata.workspace_members {
let cargo_toml = &metadata[id].manifest_path;
let crate_dir = cargo_toml
.parent()
.expect("A Cargo.toml always has a parent");
// Try to make the path relative to the workspace root so error messages
// aren't super long.
let simplified_path = crate_dir
.strip_prefix(&metadata.workspace_root)
.unwrap_or(crate_dir);

possible_paths.push(simplified_path.into());
}

Error::AmbiguousPath {
dir: dir.to_path_buf(),
Expand Down Expand Up @@ -341,7 +341,8 @@ pub enum Error {
AmbiguousPath {
/// The model directory supplied by the user.
dir: PathBuf,
/// The directories for each crate in the workspace.
/// The directories for each crate in the workspace, relative to the
/// workspace root.
possible_paths: Vec<PathBuf>,
},
}
Expand Down

0 comments on commit 6e74ae9

Please sign in to comment.