Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages for unsupported uninstall arguments #1786

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/volta-core/src/error/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ pub enum ErrorKind {
name: String,
},

/// Thrown when serializnig a bin config to JSON fails
/// Thrown when serializing a bin config to JSON fails
StringifyBinConfigError,

/// Thrown when serializnig a package config to JSON fails
/// Thrown when serializing a package config to JSON fails
StringifyPackageConfigError,

/// Thrown when serializing the platform to JSON fails
Expand Down
18 changes: 15 additions & 3 deletions src/command/uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use volta_core::error::{ExitCode, Fallible};
use volta_core::error::{ErrorKind, ExitCode, Fallible};
use volta_core::session::{ActivityKind, Session};
use volta_core::tool;
use volta_core::version::VersionSpec;
Expand All @@ -15,8 +15,20 @@ impl Command for Uninstall {
fn run(self, session: &mut Session) -> Fallible<ExitCode> {
session.add_event_start(ActivityKind::Uninstall);

let version = VersionSpec::default();
let tool = tool::Spec::from_str_and_version(&self.tool, version);
let tool = tool::Spec::try_from_str(&self.tool)?;

// For packages, specifically report that we do not support uninstalling
// specific versions. For runtimes and package managers, we currently
// *intentionally* let this fall through to inform the user that we do
// not support uninstalling those *at all*.
if let tool::Spec::Package(_name, version) = &tool {
let VersionSpec::None = version else {
return Err(ErrorKind::Unimplemented {
feature: "uninstalling specific versions of tools".into(),
}
.into());
};
}

tool.uninstall()?;

Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance/direct_uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Tests for `npm uninstall`, `npm uninstall --global`, `yarn remove`, and
//! `yarn global remove`, which we support as alternatives to `volta uninstall`
//! and which should use its logic.

use crate::support::sandbox::{sandbox, DistroMetadata, NodeFixture, Sandbox, Yarn1Fixture};
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
Expand Down
37 changes: 37 additions & 0 deletions tests/acceptance/volta_uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Tests for `volta uninstall`.

use crate::support::sandbox::{sandbox, Sandbox};
use hamcrest2::assert_that;
use hamcrest2::prelude::*;
Expand Down Expand Up @@ -94,6 +96,30 @@ fn uninstall_package_basic() {
assert!(!Sandbox::package_image_exists("cowsay"));
}

// The setup here is the same as the above, but here we check to make sure that
// if the user supplies a version, we error correctly.
#[test]
fn uninstall_package_basic_with_version() {
// basic uninstall - everything exists, and everything except the cached
// inventory files should be deleted
let s = sandbox()
.package_config("cowsay", PKG_CONFIG_BASIC)
.binary_config("cowsay", &bin_config("cowsay"))
.binary_config("cowthink", &bin_config("cowthink"))
.shim("cowsay")
.shim("cowthink")
.package_image("cowsay", "1.4.0", None)
.env(VOLTA_LOGLEVEL, "info")
.build();

assert_that!(
s.volta("uninstall [email protected]"),
execs().with_status(1).with_stderr_contains(
"[..]error: uninstalling specific versions of tools is not supported yet."
)
);
}

#[test]
fn uninstall_package_no_bins() {
// the package doesn't contain any executables, it should uninstall without error
Expand Down Expand Up @@ -178,3 +204,14 @@ fn uninstall_package_orphaned_bins() {
assert!(!Sandbox::shim_exists("cowsay"));
assert!(!Sandbox::shim_exists("cowthink"));
}

#[test]
fn uninstall_runtime() {
let s = sandbox().build();
assert_that!(
s.volta("uninstall node"),
execs()
.with_status(1)
.with_stderr_contains("[..]error: Uninstalling node is not supported yet.")
)
}
Loading