Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Better Vagrant error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Jun 25, 2020
1 parent 124b3f2 commit 4fff6ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
}
Expand Down
10 changes: 7 additions & 3 deletions src/steps/vagrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -159,8 +159,12 @@ pub fn collect_boxes(ctx: &ExecutionContext) -> Result<Vec<VagrantBox>> {
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)
Expand Down

0 comments on commit 4fff6ba

Please sign in to comment.