Skip to content

Commit

Permalink
Improve error handling when PathSource is relative
Browse files Browse the repository at this point in the history
When editing dependencies with cargo, if a relative PathSource is
supplied cargo panics with "both paths are absolute". This is the
opposite of what's actually wrong leading to confusion.

This commit changes the error message to say what is actually wrong.
  • Loading branch information
Morganamilo committed Nov 24, 2024
1 parent 9bda880 commit 6b74183
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cargo/util/toml_mut/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ fn path_field<'a>(
} else {
Cow::Borrowed(crate_root)
};
let relpath = pathdiff::diff_paths(&source.path, relative_to).expect("both paths are absolute");
let relpath = pathdiff::diff_paths(&source.path, relative_to)
.expect("PathSource::path and workspace path must be absolute");
let relpath = relpath.to_str().unwrap().replace('\\', "/");
Ok(relpath)
}
Expand Down

0 comments on commit 6b74183

Please sign in to comment.