Skip to content

Commit 4e9055c

Browse files
committed
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. Instead, use the same error formatting we use in other diff_paths calls and return that error instead of panicking.
1 parent 88edf01 commit 4e9055c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cargo/util/toml_mut/dependency.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::borrow::Cow;
44
use std::fmt::{Display, Formatter};
55
use std::path::{Path, PathBuf};
66

7+
use anyhow::Context;
78
use cargo_util_schemas::manifest::PathBaseName;
89
use indexmap::IndexSet;
910
use itertools::Itertools;
@@ -748,7 +749,13 @@ fn path_field<'a>(
748749
} else {
749750
Cow::Borrowed(crate_root)
750751
};
751-
let relpath = pathdiff::diff_paths(&source.path, relative_to).expect("both paths are absolute");
752+
let relpath = pathdiff::diff_paths(&source.path, &relative_to).with_context(|| {
753+
format!(
754+
"path comparison requires two absolute paths; path_source: `{}`, workspace_path: `{}`",
755+
source.path.display(),
756+
relative_to.display()
757+
)
758+
})?;
752759
let relpath = relpath.to_str().unwrap().replace('\\', "/");
753760
Ok(relpath)
754761
}

0 commit comments

Comments
 (0)