From 6b74183d8acf5361ff6ed35f18efb7de8800c52f Mon Sep 17 00:00:00 2001 From: morganamilo Date: Sat, 23 Nov 2024 14:16:28 +0000 Subject: [PATCH] Improve error handling when PathSource is relative 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. --- src/cargo/util/toml_mut/dependency.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml_mut/dependency.rs b/src/cargo/util/toml_mut/dependency.rs index 836fb738363..78cc58a29b7 100644 --- a/src/cargo/util/toml_mut/dependency.rs +++ b/src/cargo/util/toml_mut/dependency.rs @@ -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) }