From 5da219ed698286ae91254bb6a145e2d2e7483b8e Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Sat, 27 Feb 2021 06:41:55 +0200 Subject: [PATCH] Fix executor panic (fix #653) --- src/error.rs | 4 ++++ src/executor.rs | 6 +++--- src/runner.rs | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5018499d..30fb0947 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,6 +22,10 @@ pub enum TopgradeError { #[error("A step failed")] pub struct StepFailed; +#[derive(Error, Debug)] +#[error("Dry running")] +pub struct DryRun(); + #[derive(Error, Debug)] #[error("{0}")] pub struct SkipStep(pub String); diff --git a/src/executor.rs b/src/executor.rs index 1c601657..b568225e 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,5 +1,5 @@ //! Utilities for command execution -use crate::error::TopgradeError; +use crate::error::{DryRun, TopgradeError}; use crate::utils::{Check, CheckWithCodes}; use anyhow::Result; use log::{debug, trace}; @@ -270,7 +270,7 @@ impl CommandExt for Executor { fn check_output(&mut self) -> Result { let output = match self.output()? { ExecutorOutput::Wet(output) => output, - ExecutorOutput::Dry => unreachable!(), + ExecutorOutput::Dry => return Err(DryRun().into()), }; let status = output.status; if !status.success() { @@ -283,7 +283,7 @@ impl CommandExt for Executor { fn string_output(&mut self) -> Result { let output = match self.output()? { ExecutorOutput::Wet(output) => output, - ExecutorOutput::Dry => unreachable!(), + ExecutorOutput::Dry => return Err(DryRun().into()), }; Ok(String::from_utf8(output.stdout)?) } diff --git a/src/runner.rs b/src/runner.rs index 799accf5..2636a88a 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -1,5 +1,5 @@ use crate::ctrlc; -use crate::error::SkipStep; +use crate::error::{DryRun, SkipStep}; use crate::execution_context::ExecutionContext; use crate::report::{Report, StepResult}; use crate::{config::Step, terminal::should_retry}; @@ -39,6 +39,7 @@ impl<'a> Runner<'a> { self.report.push_result(Some((key, StepResult::Success))); break; } + Err(e) if e.downcast_ref::().is_some() => break, Err(e) if e.downcast_ref::().is_some() => { if self.ctx.config().verbose() || self.ctx.config().show_skipped() { self.report.push_result(Some((key, StepResult::Skipped(e.to_string()))));