cinderella

[unmaintained] simple CI engine
Log | Files | Refs | README | LICENSE

commit 5f93e1ecbfe411bfcb58ab05bd539674bd3b016b
parent 93a8f57225f706000affdb8af78a81fb753f0cfc
Author: Stefan Koch <programming@stefan-koch.name>
Date:   Mon, 23 Sep 2019 19:31:04 +0200

create execution error when something fails due to invalid command

Diffstat:
Msrc/execution.rs | 18++++++++++++------
Msrc/lib.rs | 9++++++---
2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/execution.rs b/src/execution.rs @@ -9,7 +9,8 @@ use crate::pipeline; pub enum ExecutionResult { NoExecution, Success, - Error(String), + BuildError(String), + ExecutionError(String), } pub fn execute<W: Write>( @@ -32,8 +33,10 @@ pub fn execute<W: Write>( executed_at_least_one = true; let res = execute_pipeline(pipeline, &variables, stdout); - if let ExecutionResult::Error(msg) = res { - return ExecutionResult::Error(msg); + if let ExecutionResult::BuildError(msg) = res { + return ExecutionResult::BuildError(msg); + } else if let ExecutionResult::ExecutionError(msg) = res { + return ExecutionResult::ExecutionError(msg); } } } @@ -61,13 +64,16 @@ fn execute_pipeline<W: Write>( let parts = split_command(&cmd); let output = Command::new(parts[0]) .args(&parts[1..]) - .output() - .expect(&format!("failed to run {}", cmd)); + .output(); + let output = match output { + Ok(output) => output, + Err(e) => return ExecutionResult::ExecutionError(e.to_string()), + }; stdout.write_all(&output.stdout).unwrap(); if !output.status.success() { - return ExecutionResult::Error( + return ExecutionResult::BuildError( String::from(format!("Pipeline failed in step: {}", cmd))); } } diff --git a/src/lib.rs b/src/lib.rs @@ -82,9 +82,12 @@ pub fn run(repo_ptr: &RepoPointer) { // configured, send a mail let res = execution::execute(&pipelines, &variables, &mut io::stdout()); - if let ExecutionResult::Error(msg) = res { - let mailer = mail::build_mailer(&config.email); - mailer.send_mail(&format!("Build failed: {}", msg)); + match res { + ExecutionResult::BuildError(msg) | ExecutionResult::ExecutionError(msg) => { + let mailer = mail::build_mailer(&config.email); + mailer.send_mail(&format!("Build failed: {}", msg)); + }, + _ => (), } } else { println!("No Cinderella configuration found");