Skip to content

Commit e40704c

Browse files
Merge pull request #1786 from volta-cli/chriskrycho/better-reporting
Better error messages for unsupported `uninstall` arguments
2 parents 0e0ef61 + 66da382 commit e40704c

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

crates/volta-core/src/error/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ pub enum ErrorKind {
443443
name: String,
444444
},
445445

446-
/// Thrown when serializnig a bin config to JSON fails
446+
/// Thrown when serializing a bin config to JSON fails
447447
StringifyBinConfigError,
448448

449-
/// Thrown when serializnig a package config to JSON fails
449+
/// Thrown when serializing a package config to JSON fails
450450
StringifyPackageConfigError,
451451

452452
/// Thrown when serializing the platform to JSON fails

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/direct_uninstall.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Tests for `npm uninstall`, `npm uninstall --global`, `yarn remove`, and
2+
//! `yarn global remove`, which we support as alternatives to `volta uninstall`
3+
//! and which should use its logic.
4+
15
use crate::support::sandbox::{sandbox, DistroMetadata, NodeFixture, Sandbox, Yarn1Fixture};
26
use hamcrest2::assert_that;
37
use hamcrest2::prelude::*;

tests/acceptance/volta_uninstall.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Tests for `volta uninstall`.
2+
13
use crate::support::sandbox::{sandbox, Sandbox};
24
use hamcrest2::assert_that;
35
use hamcrest2::prelude::*;
@@ -94,6 +96,30 @@ fn uninstall_package_basic() {
9496
assert!(!Sandbox::package_image_exists("cowsay"));
9597
}
9698

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.
101+
#[test]
102+
fn uninstall_package_basic_with_version() {
103+
// basic uninstall - everything exists, and everything except the cached
104+
// inventory files should be deleted
105+
let s = sandbox()
106+
.package_config("cowsay", PKG_CONFIG_BASIC)
107+
.binary_config("cowsay", &bin_config("cowsay"))
108+
.binary_config("cowthink", &bin_config("cowthink"))
109+
.shim("cowsay")
110+
.shim("cowthink")
111+
.package_image("cowsay", "1.4.0", None)
112+
.env(VOLTA_LOGLEVEL, "info")
113+
.build();
114+
115+
assert_that!(
116+
s.volta("uninstall [email protected]"),
117+
execs().with_status(1).with_stderr_contains(
118+
"[..]error: uninstalling specific versions of tools is not supported yet."
119+
)
120+
);
121+
}
122+
97123
#[test]
98124
fn uninstall_package_no_bins() {
99125
// the package doesn't contain any executables, it should uninstall without error
@@ -178,3 +204,14 @@ fn uninstall_package_orphaned_bins() {
178204
assert!(!Sandbox::shim_exists("cowsay"));
179205
assert!(!Sandbox::shim_exists("cowthink"));
180206
}
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)