From d32b6807c71ab01e8c5fb735dd49efc4136ac4cd Mon Sep 17 00:00:00 2001 From: Caelan Sayler Date: Sun, 1 Dec 2024 22:32:44 +0000 Subject: [PATCH] Propagate apply errors better --- src/bins/src/commands/apply.rs | 17 ++++++++--------- src/bins/src/commands/apply_windows_impl.rs | 9 +++------ src/bins/src/lib.rs | 4 ++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/bins/src/commands/apply.rs b/src/bins/src/commands/apply.rs index 7132aff2..e554a20d 100644 --- a/src/bins/src/commands/apply.rs +++ b/src/bins/src/commands/apply.rs @@ -39,19 +39,18 @@ pub fn apply<'a>( return Ok(applied_locator); } 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 => { - 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."); } diff --git a/src/bins/src/commands/apply_windows_impl.rs b/src/bins/src/commands/apply_windows_impl.rs index 47014171..637ebf1e 100644 --- a/src/bins/src/commands/apply_windows_impl.rs +++ b/src/bins/src/commands/apply_windows_impl.rs @@ -6,10 +6,7 @@ use crate::{ }; use anyhow::{bail, Context, Result}; use std::sync::mpsc; -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::{fs, path::PathBuf}; use velopack::{bundle::load_bundle_from_file, constants, locator::VelopackLocator}; // fn ropycopy, P2: AsRef>(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 info!("Backing up current dir to {}", &temp_path_old.to_string_lossy()); shared::retry_io_ex(|| fs::rename(¤t_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; // if let Err(e) = fs::rename(¤t_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... info!("Replacing current dir with {}", &temp_path_new.to_string_lossy()); shared::retry_io_ex(|| fs::rename(&temp_path_new, ¤t_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 we didn't need robocopy for the backup, we don't need it for the deploy hopefully diff --git a/src/bins/src/lib.rs b/src/bins/src/lib.rs index de993cc3..d29d4345 100644 --- a/src/bins/src/lib.rs +++ b/src/bins/src/lib.rs @@ -4,10 +4,10 @@ pub mod shared; #[cfg(target_os = "windows")] pub mod windows; -pub use shared::{dialogs}; +pub use shared::dialogs; #[macro_use] extern crate log; extern crate simplelog; #[macro_use] -extern crate lazy_static; \ No newline at end of file +extern crate lazy_static;