Fix "WSL already reported" panic (#1344)
This commit is contained in:
@@ -1,15 +1,34 @@
|
||||
use crate::ctrlc;
|
||||
use crate::error::{DryRun, SkipStep};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::report::{Report, StepResult};
|
||||
use crate::step::Step;
|
||||
use crate::terminal::print_error;
|
||||
use crate::terminal::should_retry;
|
||||
use color_eyre::eyre::Result;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Debug;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::ctrlc;
|
||||
use crate::error::{DryRun, SkipStep};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::step::Step;
|
||||
use crate::terminal::{print_error, should_retry};
|
||||
|
||||
pub enum StepResult {
|
||||
Success,
|
||||
Failure,
|
||||
Ignored,
|
||||
Skipped(String),
|
||||
}
|
||||
|
||||
impl StepResult {
|
||||
pub fn failed(&self) -> bool {
|
||||
use StepResult::*;
|
||||
|
||||
match self {
|
||||
Success | Ignored | Skipped(_) => false,
|
||||
Failure => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Report<'a> = Vec<(Cow<'a, str>, StepResult)>;
|
||||
|
||||
pub struct Runner<'a> {
|
||||
ctx: &'a ExecutionContext<'a>,
|
||||
report: Report<'a>,
|
||||
@@ -19,20 +38,25 @@ impl<'a> Runner<'a> {
|
||||
pub fn new(ctx: &'a ExecutionContext) -> Runner<'a> {
|
||||
Runner {
|
||||
ctx,
|
||||
report: Report::new(),
|
||||
report: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute<F, M>(&mut self, step: Step, key: M, func: F) -> Result<()>
|
||||
fn push_result(&mut self, key: Cow<'a, str>, result: StepResult) {
|
||||
debug_assert!(!self.report.iter().any(|(k, _)| k == &key), "{key} already reported");
|
||||
self.report.push((key, result));
|
||||
}
|
||||
|
||||
pub fn execute<K, F>(&mut self, step: Step, key: K, func: F) -> Result<()>
|
||||
where
|
||||
K: Into<Cow<'a, str>> + Debug,
|
||||
F: Fn() -> Result<()>,
|
||||
M: Into<Cow<'a, str>> + Debug,
|
||||
{
|
||||
if !self.ctx.config().should_run(step) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let key = key.into();
|
||||
let key: Cow<'a, str> = key.into();
|
||||
debug!("Step {:?}", key);
|
||||
|
||||
// alter the `func` to put it in a span
|
||||
@@ -46,13 +70,13 @@ impl<'a> Runner<'a> {
|
||||
loop {
|
||||
match func() {
|
||||
Ok(()) => {
|
||||
self.report.push_result(Some((key, StepResult::Success)));
|
||||
self.push_result(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()))));
|
||||
self.push_result(key, StepResult::Skipped(e.to_string()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -73,14 +97,14 @@ impl<'a> Runner<'a> {
|
||||
};
|
||||
|
||||
if !should_retry {
|
||||
self.report.push_result(Some((
|
||||
self.push_result(
|
||||
key,
|
||||
if ignore_failure {
|
||||
StepResult::Ignored
|
||||
} else {
|
||||
StepResult::Failure
|
||||
},
|
||||
)));
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user