Skip to content

Commit

Permalink
Improve error messages for uv remove
Browse files Browse the repository at this point in the history
Closes #9958
  • Loading branch information
zanieb committed Dec 17, 2024
1 parent 9e4b842 commit 2f9ba08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
21 changes: 13 additions & 8 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub(crate) async fn remove(
if deps.is_empty() {
warn_if_present(&package, &toml);
anyhow::bail!(
"The dependency `{package}` could not be found in `dependencies`"
"The dependency `{package}` could not be found in `project.dependencies`"
);
}
}
Expand All @@ -123,7 +123,7 @@ pub(crate) async fn remove(
if dev_deps.is_empty() && group_deps.is_empty() {
warn_if_present(&package, &toml);
anyhow::bail!(
"The dependency `{package}` could not be found in `dev-dependencies` or `dependency-groups.dev`"
"The dependency `{package}` could not be found in `tool.uv.dev-dependencies` or `tool.uv.dependency-groups.dev`"
);
}
}
Expand All @@ -132,7 +132,7 @@ pub(crate) async fn remove(
if deps.is_empty() {
warn_if_present(&package, &toml);
anyhow::bail!(
"The dependency `{package}` could not be found in `optional-dependencies`"
"The dependency `{package}` could not be found in `project.optional-dependencies.{extra}`"
);
}
}
Expand All @@ -144,15 +144,15 @@ pub(crate) async fn remove(
if dev_deps.is_empty() && group_deps.is_empty() {
warn_if_present(&package, &toml);
anyhow::bail!(
"The dependency `{package}` could not be found in `dev-dependencies` or `dependency-groups.dev`"
"The dependency `{package}` could not be found in `tool.uv.dev-dependencies` or `tool.uv.dependency-groups.dev`"
);
}
} else {
let deps = toml.remove_dependency_group_requirement(&package, group)?;
if deps.is_empty() {
warn_if_present(&package, &toml);
anyhow::bail!(
"The dependency `{package}` could not be found in `dependency-groups`"
"The dependency `{package}` could not be found in `dependency-groups.{group}`"
);
}
}
Expand Down Expand Up @@ -323,16 +323,21 @@ fn warn_if_present(name: &PackageName, pyproject: &PyProjectTomlMut) {
warn_user!("`{name}` is a production dependency");
}
DependencyType::Dev => {
warn_user!("`{name}` is a development dependency; try calling `uv remove --dev`");
warn_user!(
"`{name}` is a development dependency (try: `{}`)",
format!("uv remove {name} --dev`").bold()
);
}
DependencyType::Optional(group) => {
warn_user!(
"`{name}` is an optional dependency; try calling `uv remove --optional {group}`",
"`{name}` is an optional dependency (try: `{}`)",
format!("uv remove {name} --optional {group}").bold()
);
}
DependencyType::Group(group) => {
warn_user!(
"`{name}` is in the `{group}` group; try calling `uv remove --group {group}`",
"`{name}` is in the `{group}` group (try: `{}`)",
format!("uv remove {name} --group {group}").bold()
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ fn add_remove_dev() -> Result<()> {
----- stderr -----
warning: `anyio` is in the `dev` group; try calling `uv remove --group dev`
error: The dependency `anyio` could not be found in `dependencies`
error: The dependency `anyio` could not be found in `project.dependencies`
"###);

// Remove the dependency.
Expand Down Expand Up @@ -1337,7 +1337,7 @@ fn add_remove_optional() -> Result<()> {
----- stderr -----
warning: `anyio` is an optional dependency; try calling `uv remove --optional io`
error: The dependency `anyio` could not be found in `dependencies`
error: The dependency `anyio` could not be found in `project.dependencies`
"###);

// Remove the dependency.
Expand Down Expand Up @@ -4817,7 +4817,7 @@ fn remove_group() -> Result<()> {
----- stdout -----
----- stderr -----
error: The dependency `anyio` could not be found in `dependency-groups`
error: The dependency `anyio` could not be found in `dependency-groups.test`
"###);

let pyproject_toml = context.read("pyproject.toml");
Expand Down Expand Up @@ -4845,7 +4845,7 @@ fn remove_group() -> Result<()> {
----- stdout -----
----- stderr -----
error: The dependency `anyio` could not be found in `dependency-groups`
error: The dependency `anyio` could not be found in `dependency-groups.test`
"###);

let pyproject_toml = context.temp_dir.child("pyproject.toml");
Expand All @@ -4864,7 +4864,7 @@ fn remove_group() -> Result<()> {
----- stderr -----
warning: `anyio` is a production dependency
error: The dependency `anyio` could not be found in `dependency-groups`
error: The dependency `anyio` could not be found in `dependency-groups.test`
"###);

Ok(())
Expand Down

0 comments on commit 2f9ba08

Please sign in to comment.