Skip to content

Commit

Permalink
added better task error handling. tasks stop executing on failure now
Browse files Browse the repository at this point in the history
  • Loading branch information
CraZySacX committed Feb 16, 2024
1 parent 761042a commit 1d1f54b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
name = "cargo-matrix"
readme = "README.md"
repository = "/~https://github.com/rustyhorde/cargo-matrix"
version = "0.2.0"
version = "0.2.1"

[package.metadata.binstall]

Expand Down
13 changes: 11 additions & 2 deletions src/runtime/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ pub(crate) enum TaskKind {
Test,
}

#[derive(Clone, Copy, Debug)]
pub(crate) enum TaskResult {
Success,
Fail(i32),
}

pub(crate) struct Task {
kind: TaskKind,
package: String,
Expand Down Expand Up @@ -59,7 +65,7 @@ impl Task {
}
}

pub(crate) fn execute(self) -> Result<()> {
pub(crate) fn execute(self) -> Result<TaskResult> {
for feature_set in self.matrix {
match self.kind {
TaskKind::Build => print!("{}", Paint::cyan(" Building ").bold()),
Expand Down Expand Up @@ -118,11 +124,14 @@ impl Task {
let output = cmd.output()?;
if output.status.success() {
on_success();
} else {
let code = output.status.code().unwrap_or(-1);
return Ok(TaskResult::Fail(code));
}
}
}

Ok(())
Ok(TaskResult::Success)
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use self::cli::{Cargo, CargoSubcommands};
use crate::{
config::Config,
feature::FeatureMatrix,
runtime::execute::{Task, TaskKind},
runtime::execute::{Task, TaskKind, TaskResult},
};
use anyhow::{anyhow, Result};
use cargo_metadata::{Metadata, MetadataCommand, Package};
Expand Down Expand Up @@ -116,7 +116,7 @@ where

// Execute the task against the matricies
for (package, matrix) in matricies {
Task::new(
let task_result = Task::new(
task_kind,
package.name.clone(),
matrix,
Expand All @@ -125,6 +125,10 @@ where
*matrix_args.dry_run(),
)
.execute()?;
match task_result {
TaskResult::Success => continue,
TaskResult::Fail(code) => return Err(anyhow!("task failed: {}", code)),
}
}
}
}
Expand Down

0 comments on commit 1d1f54b

Please sign in to comment.