Improve messaging on install failures and reverts (#118)

This commit is contained in:
Ana Hobden 2022-12-13 09:11:46 -08:00 committed by GitHub
parent fab886cf4d
commit e2e841ab8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View file

@ -136,12 +136,29 @@ impl CommandExecute for Install {
if let Some(expected) = err.expected() { if let Some(expected) = err.expected() {
was_expected = true; was_expected = true;
eprintln!("{}", expected.red()) eprintln!("{}", expected.red())
} else {
println!(
"\
{success}\n\
To get started using Nix, open a new shell or run `{shell_reminder}`\n\
",
success = "Nix was installed successfully!".green().bold(),
shell_reminder = match std::env::var("SHELL") {
Ok(val) if val.contains("fish") =>
". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish"
.bold(),
Ok(_) | Err(_) =>
". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh".bold(),
},
);
} }
if !was_expected { if !was_expected {
let error = eyre!(err).wrap_err("Install failure"); let error = eyre!(err).wrap_err("Install failure");
tracing::error!("{:?}", error); tracing::error!("{:?}", error);
}; };
eprintln!("{}", "Installation failure, offering to revert...".red());
if !interaction::confirm( if !interaction::confirm(
install_plan install_plan
.describe_uninstall(explain) .describe_uninstall(explain)
@ -161,6 +178,15 @@ impl CommandExecute for Install {
return Ok(ExitCode::FAILURE); return Ok(ExitCode::FAILURE);
} }
return Err(e.into()); return Err(e.into());
} else {
println!(
"\
{message}\n\
",
message = "Partial Nix install was uninstalled successfully!"
.white()
.bold(),
);
} }
} else { } else {
if let Some(expected) = err.expected() { if let Some(expected) = err.expected() {
@ -173,20 +199,6 @@ impl CommandExecute for Install {
} }
} }
println!(
"\
{success}\n\
To get started using Nix, open a new shell or run `{shell_reminder}`\n\
",
success = "Nix was installed successfully!".green().bold(),
shell_reminder = match std::env::var("SHELL") {
Ok(val) if val.contains("fish") =>
". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish".bold(),
Ok(_) | Err(_) =>
". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh".bold(),
},
);
Ok(ExitCode::SUCCESS) Ok(ExitCode::SUCCESS)
} }
} }

View file

@ -66,7 +66,7 @@ impl HasExpectedErrors for HarmonicError {
HarmonicError::RecordingReceipt(_, _) => None, HarmonicError::RecordingReceipt(_, _) => None,
HarmonicError::CopyingSelf(_) => None, HarmonicError::CopyingSelf(_) => None,
HarmonicError::SerializingReceipt(_) => None, HarmonicError::SerializingReceipt(_) => None,
HarmonicError::Cancelled => None, this @ HarmonicError::Cancelled => Some(Box::new(this)),
HarmonicError::SemVer(_) => None, HarmonicError::SemVer(_) => None,
HarmonicError::Planner(planner_error) => planner_error.expected(), HarmonicError::Planner(planner_error) => planner_error.expected(),
HarmonicError::InstallSettings(_) => None, HarmonicError::InstallSettings(_) => None,