From 4fff6ba56ff5a96ca1f81b5447735e325800c82d Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Thu, 25 Jun 2020 08:37:29 +0300 Subject: [PATCH] Better Vagrant error handling --- src/error.rs | 3 +++ src/executor.rs | 3 ++- src/steps/vagrant.rs | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7558ee08..2114b80f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,9 @@ pub enum TopgradeError { #[error("{0}")] ProcessFailed(ExitStatus), + #[error("{0}: {1}")] + ProcessFailedWithOutput(ExitStatus, String), + #[error("Sudo is required for this step")] #[allow(dead_code)] SudoRequired, diff --git a/src/executor.rs b/src/executor.rs index 400d585d..e9ef47de 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -245,7 +245,8 @@ impl CommandExt for Command { trace!("Output of {:?}: {:?}", self, output); let status = output.status; if !status.success() { - return Err(TopgradeError::ProcessFailed(status).into()); + let stderr = String::from_utf8(output.stderr).unwrap_or_default(); + return Err(TopgradeError::ProcessFailedWithOutput(status, stderr).into()); } Ok(String::from_utf8(output.stdout)?) } diff --git a/src/steps/vagrant.rs b/src/steps/vagrant.rs index 0851b7d5..1415f9da 100644 --- a/src/steps/vagrant.rs +++ b/src/steps/vagrant.rs @@ -3,7 +3,7 @@ use crate::executor::CommandExt; use crate::terminal::print_separator; use crate::{error::SkipStep, utils}; use anyhow::Result; -use log::debug; +use log::{debug, error}; use std::path::{Path, PathBuf}; use std::process::Command; use std::{fmt::Display, rc::Rc, str::FromStr}; @@ -159,8 +159,12 @@ pub fn collect_boxes(ctx: &ExecutionContext) -> Result> { let mut result = Vec::new(); for directory in directories { - let mut boxes = vagrant.get_boxes(directory)?; - result.append(&mut boxes); + match vagrant.get_boxes(directory) { + Ok(mut boxes) => { + result.append(&mut boxes); + } + Err(e) => error!("Error collecting vagrant boxes from {}: {}", directory, e), + }; } Ok(result)