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

Commit

Permalink
Fix executor panic (fix #653)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Feb 27, 2021
1 parent 23d9a5b commit 5da219e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/executor.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -270,7 +270,7 @@ impl CommandExt for Executor {
fn check_output(&mut self) -> Result<String> {
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() {
Expand All @@ -283,7 +283,7 @@ impl CommandExt for Executor {
fn string_output(&mut self) -> Result<String> {
let output = match self.output()? {
ExecutorOutput::Wet(output) => output,
ExecutorOutput::Dry => unreachable!(),
ExecutorOutput::Dry => return Err(DryRun().into()),
};
Ok(String::from_utf8(output.stdout)?)
}
Expand Down
3 changes: 2 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -39,6 +39,7 @@ impl<'a> Runner<'a> {
self.report.push_result(Some((key, StepResult::Success)));
break;
}
Err(e) if e.downcast_ref::<DryRun>().is_some() => break,
Err(e) if e.downcast_ref::<SkipStep>().is_some() => {
if self.ctx.config().verbose() || self.ctx.config().show_skipped() {
self.report.push_result(Some((key, StepResult::Skipped(e.to_string()))));
Expand Down

0 comments on commit 5da219e

Please sign in to comment.