From 26cee7066649348546599249a1c1a103d130081b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 10 Dec 2020 11:50:27 +0100 Subject: Add printing of script error message Signed-off-by: Matthias Beyer --- src/endpoint/configured.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/endpoint/configured.rs') diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index a478857..d9b293d 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -291,7 +291,7 @@ impl Endpoint { .with_context(|| anyhow!("Copying artifacts to container {}", container_id))?; } - let exited_successfully: Option = container + let exited_successfully: Option<(bool, Option)> = container .copy_file_into(script_path, job.script().as_ref().as_bytes()) .inspect(|r| { trace!("Copying script to container {} -> {:?}", container_id, r); }) .map(|r| r.with_context(|| anyhow!("Copying the script into the container {} on '{}'", container_id, self.name))) @@ -315,8 +315,8 @@ impl Endpoint { let mut exited_successfully = None; { match item { - LogItem::State(Ok(_)) => exited_successfully = Some(true), - LogItem::State(Err(_)) => exited_successfully = Some(false), + LogItem::State(Ok(_)) => exited_successfully = Some((true, None)), + LogItem::State(Err(ref msg)) => exited_successfully = Some((false, Some(msg.clone()))), _ => { // Nothing } @@ -338,11 +338,11 @@ impl Endpoint { .with_context(|| anyhow!("Copying script to container, running container and getting logs: {}", container_id))? .into_iter() .fold(None, |accu, elem| match (accu, elem) { - (None , b) => b, - (Some(false) , _) => Some(false), - (_ , Some(false)) => Some(false), - (a , None) => a, - (Some(true) , Some(true)) => Some(true), + (None , b) => b, + (Some((false, msg)) , _) => Some((false, msg)), + (_ , Some((false, msg))) => Some((false, msg)), + (a , None) => a, + (Some((true, _)) , Some((true, _))) => Some((true, None)), }); trace!("Fetching /outputs from container {}", container_id); @@ -364,8 +364,11 @@ impl Endpoint { let script: Script = job.script().clone(); match exited_successfully { - Some(false) => Err(ContainerError::container_error(ContainerHash::from(container_id), self.uri().clone())).map_err(Error::from), - Some(true) | None => { + Some((false, msg)) => Err({ + ContainerError::container_error(ContainerHash::from(container_id), self.uri().clone(), msg.unwrap_or_else(|| String::new())) + }).map_err(Error::from), + + Some((true, _)) | None => { container.stop(Some(std::time::Duration::new(1, 0))) .await .with_context(|| anyhow!("Stopping container {}", container_id))?; -- cgit v1.2.3