aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornotgne22020-10-29 19:40:53 -0700
committernotgne22020-10-29 19:40:53 -0700
commit5ba58e03283f4fe5f34df414a33944530ce2b943 (patch)
tree5c42d59b2e8620b824a6da41104dd8b9b5327dea /src
parentca86bab9e9e8a0e60cec6793147abaec44a0ea8f (diff)
Remove last remaining inappropriate panics
Diffstat (limited to 'src')
-rw-r--r--src/activate.rs35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/activate.rs b/src/activate.rs
index b7bf61f..aa63b6e 100644
--- a/src/activate.rs
+++ b/src/activate.rs
@@ -261,14 +261,23 @@ pub enum ActivateError {
SetProfileError(std::io::Error),
#[error("The command for setting profile resulted in a bad exit code: {0:?}")]
SetProfileExitError(Option<i32>),
+
+ #[error("Failed to run bootstrap command: {0}")]
+ BootstrapError(std::io::Error),
+ #[error("The bootstrap command resulted in a bad exit code: {0:?}")]
+ BootstrapExitError(Option<i32>),
+
#[error("Error removing profile after bootstrap failed: {0}")]
RemoveGenerationErr(std::io::Error),
+
#[error("Failed to execute the activation script: {0}")]
RunActivateError(std::io::Error),
#[error("The activation script resulted in a bad exit code: {0:?}")]
RunActivateExitError(Option<i32>),
+
#[error("There was an error de-activating after an error was encountered: {0}")]
DeactivateError(#[from] DeactivateError),
+
#[error("Failed to get activation confirmation: {0}")]
ActivationConfirmationError(#[from] ActivationConfirmationError),
}
@@ -294,9 +303,13 @@ pub async fn activate(
.await
.map_err(ActivateError::SetProfileError)?;
- if !nix_env_set_exit_status.success() {
- good_panic!("Failed to update nix-env generation");
- }
+ match nix_env_set_exit_status.code() {
+ Some(0) => (),
+ a => {
+ deactivate(&profile_path).await?;
+ return Err(ActivateError::SetProfileExitError(a));
+ }
+ };
if let (Some(bootstrap_cmd), false) = (bootstrap_cmd, !Path::new(&profile_path).exists()) {
let bootstrap_status = Command::new("bash")
@@ -309,12 +322,22 @@ pub async fn activate(
.await;
match bootstrap_status {
- Ok(s) if s.success() => (),
- _ => {
+ Ok(s) => match s.code() {
+ Some(0) => {}
+ a => {
+ tokio::fs::remove_file(&profile_path)
+ .await
+ .map_err(ActivateError::RemoveGenerationErr)?;
+
+ return Err(ActivateError::BootstrapExitError(a));
+ }
+ },
+ Err(err) => {
tokio::fs::remove_file(&profile_path)
.await
.map_err(ActivateError::RemoveGenerationErr)?;
- good_panic!("Failed to execute bootstrap command");
+
+ return Err(ActivateError::BootstrapError(err));
}
}
}