Skip to content

Commit

Permalink
Improve error handling when PathSource is relative (#14854)
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.

Instead, use the same error formatting we use in other diff_paths calls
and return that error instead of panicking.
  • Loading branch information
weihanglo authored Nov 24, 2024
2 parents 9bda880 + 6b74183 commit f1767d0
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
@@ -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)
}

0 comments on commit f1767d0

Please sign in to comment.