Propagate apply errors better

This commit is contained in:
Caelan Sayler
2024-12-01 22:32:44 +00:00
committed by Caelan
parent 36e80fc8fb
commit d32b6807c7
3 changed files with 13 additions and 17 deletions

View File

@@ -39,19 +39,18 @@ pub fn apply<'a>(
return Ok(applied_locator); return Ok(applied_locator);
} }
Err(e) => { Err(e) => {
error!("Error applying package: {}", e); if restart {
shared::start_package(&locator, exe_args, Some(constants::HOOK_ENV_RESTART))?;
}
bail!("Error applying package: {}", e);
} }
} }
} }
None => { None => {
error!("Failed to locate full package to apply. Please provide with the --package {{path}} argument"); if restart {
shared::start_package(&locator, exe_args, Some(constants::HOOK_ENV_RESTART))?;
}
bail!("Failed to locate full package to apply. Please provide with the --package {{path}} argument");
} }
} }
// an error occurred if we're here, but we still want to restart the old version of the app if it was requested
if restart {
shared::start_package(&locator, exe_args, Some(constants::HOOK_ENV_RESTART))?;
}
bail!("Apply failed, see logs for details.");
} }

View File

@@ -6,10 +6,7 @@ use crate::{
}; };
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use std::sync::mpsc; use std::sync::mpsc;
use std::{ use std::{fs, path::PathBuf};
fs,
path::{Path, PathBuf},
};
use velopack::{bundle::load_bundle_from_file, constants, locator::VelopackLocator}; use velopack::{bundle::load_bundle_from_file, constants, locator::VelopackLocator};
// fn ropycopy<P1: AsRef<Path>, P2: AsRef<Path>>(source: &P1, dest: &P2) -> Result<()> { // fn ropycopy<P1: AsRef<Path>, P2: AsRef<Path>>(source: &P1, dest: &P2) -> Result<()> {
@@ -94,7 +91,7 @@ pub fn apply_package_impl(old_locator: &VelopackLocator, package: &PathBuf, run_
// fourth, we make as backup of the current dir to temp_path_old // fourth, we make as backup of the current dir to temp_path_old
info!("Backing up current dir to {}", &temp_path_old.to_string_lossy()); info!("Backing up current dir to {}", &temp_path_old.to_string_lossy());
shared::retry_io_ex(|| fs::rename(&current_dir, &temp_path_old), 1000, 10) shared::retry_io_ex(|| fs::rename(&current_dir, &temp_path_old), 1000, 10)
.context("Unable to start the update, because one or more running processes prevented it.")?; .context("Unable to start the update, because one or more running processes prevented it. Try again later, or if the issue persists, restart your computer.")?;
// let mut requires_robocopy = false; // let mut requires_robocopy = false;
// if let Err(e) = fs::rename(&current_dir, &temp_path_old) { // if let Err(e) = fs::rename(&current_dir, &temp_path_old) {
@@ -107,7 +104,7 @@ pub fn apply_package_impl(old_locator: &VelopackLocator, package: &PathBuf, run_
// if this fails we will yolo a rollback... // if this fails we will yolo a rollback...
info!("Replacing current dir with {}", &temp_path_new.to_string_lossy()); info!("Replacing current dir with {}", &temp_path_new.to_string_lossy());
shared::retry_io_ex(|| fs::rename(&temp_path_new, &current_dir), 1000, 30) shared::retry_io_ex(|| fs::rename(&temp_path_new, &current_dir), 1000, 30)
.context("Unable to complete the update, and the app was left in a broken state. You may need to re-install")?; .context("Unable to complete the update, and the app was left in a broken state. You may need to re-install or repair this application manually.")?;
// if !requires_robocopy { // if !requires_robocopy {
// // if we didn't need robocopy for the backup, we don't need it for the deploy hopefully // // if we didn't need robocopy for the backup, we don't need it for the deploy hopefully

View File

@@ -4,10 +4,10 @@ pub mod shared;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub mod windows; pub mod windows;
pub use shared::{dialogs}; pub use shared::dialogs;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate simplelog; extern crate simplelog;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;