Skip to content

Commit 66da382

Browse files
committed
Better error messages for unsupported uninstall arguments
Instead of parsing whatever string the user supplied as the tool name and supplying a default `VersionSpec`, attempt to parse the value as a full specifier which may include a version. This means we can provide better errors when the user passes a version. Specifically we can report that Volta does not yet support uninstalling specific versions of tools. Previously, we would report something like this: ``` warning: No package '[email protected]' found to uninstall ``` Notice that the old message treated `'[email protected]'` as the name of the tool, when it should have been treating it as a tool and a version specifier. Now, we instead report that uninstalling specific versions of tools is unsupported. The original motivation here was noticing that we printed errors like that if the user tried to uninstall a runtime or a package manager with a version specifier. This fixes that as well, since it no longer parses a string like `[email protected]` as a package, but rather as a runtime and version specifier, and can fall into the normal handling for runtimes.
1 parent fd8cc68 commit 66da382

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/command/uninstall.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use volta_core::error::{ExitCode, Fallible};
1+
use volta_core::error::{ErrorKind, ExitCode, Fallible};
22
use volta_core::session::{ActivityKind, Session};
33
use volta_core::tool;
44
use volta_core::version::VersionSpec;
@@ -15,8 +15,20 @@ impl Command for Uninstall {
1515
fn run(self, session: &mut Session) -> Fallible<ExitCode> {
1616
session.add_event_start(ActivityKind::Uninstall);
1717

18-
let version = VersionSpec::default();
19-
let tool = tool::Spec::from_str_and_version(&self.tool, version);
18+
let tool = tool::Spec::try_from_str(&self.tool)?;
19+
20+
// For packages, specifically report that we do not support uninstalling
21+
// specific versions. For runtimes and package managers, we currently
22+
// *intentionally* let this fall through to inform the user that we do
23+
// not support uninstalling those *at all*.
24+
if let tool::Spec::Package(_name, version) = &tool {
25+
let VersionSpec::None = version else {
26+
return Err(ErrorKind::Unimplemented {
27+
feature: "uninstalling specific versions of tools".into(),
28+
}
29+
.into());
30+
};
31+
}
2032

2133
tool.uninstall()?;
2234

tests/acceptance/volta_uninstall.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ fn uninstall_package_basic() {
9696
assert!(!Sandbox::package_image_exists("cowsay"));
9797
}
9898

99+
// The setup here is the same as the above, but here we check to make sure that
100+
// if the user supplies a version, we error correctly.
99101
#[test]
100102
fn uninstall_package_basic_with_version() {
101103
// basic uninstall - everything exists, and everything except the cached
@@ -116,14 +118,6 @@ fn uninstall_package_basic_with_version() {
116118
"[..]error: uninstalling specific versions of tools is not supported yet."
117119
)
118120
);
119-
120-
// check that nothing is deleted.
121-
assert!(Sandbox::package_config_exists("cowsay"));
122-
assert!(Sandbox::bin_config_exists("cowsay"));
123-
assert!(Sandbox::bin_config_exists("cowthink"));
124-
assert!(Sandbox::shim_exists("cowsay"));
125-
assert!(Sandbox::shim_exists("cowthink"));
126-
assert!(Sandbox::package_image_exists("cowsay"));
127121
}
128122

129123
#[test]
@@ -210,3 +204,14 @@ fn uninstall_package_orphaned_bins() {
210204
assert!(!Sandbox::shim_exists("cowsay"));
211205
assert!(!Sandbox::shim_exists("cowthink"));
212206
}
207+
208+
#[test]
209+
fn uninstall_runtime() {
210+
let s = sandbox().build();
211+
assert_that!(
212+
s.volta("uninstall node"),
213+
execs()
214+
.with_status(1)
215+
.with_stderr_contains("[..]error: Uninstalling node is not supported yet.")
216+
)
217+
}

0 commit comments

Comments
 (0)