Fix executor panic (fix #653)
This commit is contained in:
@@ -22,6 +22,10 @@ pub enum TopgradeError {
|
|||||||
#[error("A step failed")]
|
#[error("A step failed")]
|
||||||
pub struct StepFailed;
|
pub struct StepFailed;
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
#[error("Dry running")]
|
||||||
|
pub struct DryRun();
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
pub struct SkipStep(pub String);
|
pub struct SkipStep(pub String);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//! Utilities for command execution
|
//! Utilities for command execution
|
||||||
use crate::error::TopgradeError;
|
use crate::error::{DryRun, TopgradeError};
|
||||||
use crate::utils::{Check, CheckWithCodes};
|
use crate::utils::{Check, CheckWithCodes};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
@@ -270,7 +270,7 @@ impl CommandExt for Executor {
|
|||||||
fn check_output(&mut self) -> Result<String> {
|
fn check_output(&mut self) -> Result<String> {
|
||||||
let output = match self.output()? {
|
let output = match self.output()? {
|
||||||
ExecutorOutput::Wet(output) => output,
|
ExecutorOutput::Wet(output) => output,
|
||||||
ExecutorOutput::Dry => unreachable!(),
|
ExecutorOutput::Dry => return Err(DryRun().into()),
|
||||||
};
|
};
|
||||||
let status = output.status;
|
let status = output.status;
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
@@ -283,7 +283,7 @@ impl CommandExt for Executor {
|
|||||||
fn string_output(&mut self) -> Result<String> {
|
fn string_output(&mut self) -> Result<String> {
|
||||||
let output = match self.output()? {
|
let output = match self.output()? {
|
||||||
ExecutorOutput::Wet(output) => output,
|
ExecutorOutput::Wet(output) => output,
|
||||||
ExecutorOutput::Dry => unreachable!(),
|
ExecutorOutput::Dry => return Err(DryRun().into()),
|
||||||
};
|
};
|
||||||
Ok(String::from_utf8(output.stdout)?)
|
Ok(String::from_utf8(output.stdout)?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::ctrlc;
|
use crate::ctrlc;
|
||||||
use crate::error::SkipStep;
|
use crate::error::{DryRun, SkipStep};
|
||||||
use crate::execution_context::ExecutionContext;
|
use crate::execution_context::ExecutionContext;
|
||||||
use crate::report::{Report, StepResult};
|
use crate::report::{Report, StepResult};
|
||||||
use crate::{config::Step, terminal::should_retry};
|
use crate::{config::Step, terminal::should_retry};
|
||||||
@@ -39,6 +39,7 @@ impl<'a> Runner<'a> {
|
|||||||
self.report.push_result(Some((key, StepResult::Success)));
|
self.report.push_result(Some((key, StepResult::Success)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Err(e) if e.downcast_ref::<DryRun>().is_some() => break,
|
||||||
Err(e) if e.downcast_ref::<SkipStep>().is_some() => {
|
Err(e) if e.downcast_ref::<SkipStep>().is_some() => {
|
||||||
if self.ctx.config().verbose() || self.ctx.config().show_skipped() {
|
if self.ctx.config().verbose() || self.ctx.config().show_skipped() {
|
||||||
self.report.push_result(Some((key, StepResult::Skipped(e.to_string()))));
|
self.report.push_result(Some((key, StepResult::Skipped(e.to_string()))));
|
||||||
|
|||||||
Reference in New Issue
Block a user