Skip to content

Commit f1767d0

Browse files
authored
Improve error handling when PathSource is relative (#14854)
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.
2 parents 9bda880 + 6b74183 commit f1767d0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/cargo/util/toml_mut/dependency.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ fn path_field<'a>(
748748
} else {
749749
Cow::Borrowed(crate_root)
750750
};
751-
let relpath = pathdiff::diff_paths(&source.path, relative_to).expect("both paths are absolute");
751+
let relpath = pathdiff::diff_paths(&source.path, relative_to)
752+
.expect("PathSource::path and workspace path must be absolute");
752753
let relpath = relpath.to_str().unwrap().replace('\\', "/");
753754
Ok(relpath)
754755
}

0 commit comments

Comments
 (0)