summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-09-15 10:23:12 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-09-23 12:51:30 +0200
commitb1137c967130715d68b40b332151d913be6ebbab (patch)
tree590d1a6250cd7e1933b85dc582087e0dbc9556f0
parent56a22ff903df0d881bce88bf68cdb4de8bab06c1 (diff)
Add helper for displaying maps of errors
This patch adds a helper trait to display maps from UUID -> Error. It is just introduced for convenience and less code duplication, the speed of execution is not relevant at all in this case, as if this code is executed, we're already handling errors and aborting the execution anyways. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/orchestrator/mod.rs3
-rw-r--r--src/orchestrator/orchestrator.rs5
-rw-r--r--src/orchestrator/util.rs38
3 files changed, 44 insertions, 2 deletions
diff --git a/src/orchestrator/mod.rs b/src/orchestrator/mod.rs
index 773ffe2..523a037 100644
--- a/src/orchestrator/mod.rs
+++ b/src/orchestrator/mod.rs
@@ -11,3 +11,6 @@
#![allow(clippy::module_inception)]
mod orchestrator;
pub use orchestrator::*;
+
+mod util;
+
diff --git a/src/orchestrator/orchestrator.rs b/src/orchestrator/orchestrator.rs
index 0f2e528..3493403 100644
--- a/src/orchestrator/orchestrator.rs
+++ b/src/orchestrator/orchestrator.rs
@@ -43,6 +43,7 @@ use crate::filestore::StagingStore;
use crate::job::Dag;
use crate::job::JobDefinition;
use crate::job::RunnableJob;
+use crate::orchestrator::util::*;
use crate::source::SourceCache;
use crate::util::EnvironmentVariableName;
use crate::util::progress::ProgressBars;
@@ -591,14 +592,14 @@ impl<'a> JobTask<'a> {
// receive from the receiver
let continue_receiving = self.perform_receive(&mut received_dependencies, &mut received_errors).await?;
- trace!("[{}]: Received errors = {:?}", self.jobdef.job.uuid(), received_errors);
+ trace!("[{}]: Received errors = {}", self.jobdef.job.uuid(), received_errors.display_error_map());
// if there are any errors from child tasks
if !received_errors.is_empty() {
// send them to the parent,...
//
// We only send to one parent, because it doesn't matter
// And we know that we have at least one sender
- log::error!("[{}]: Received errors = {:?}", self.jobdef.job.uuid(), received_errors);
+ log::error!("[{}]: Received errors = {}", self.jobdef.job.uuid(), received_errors.display_error_map());
self.sender[0].send(Err(received_errors)).await;
// ... and stop operation, because the whole tree will fail anyways.
diff --git a/src/orchestrator/util.rs b/src/orchestrator/util.rs
new file mode 100644
index 0000000..2b20694
--- /dev/null
+++ b/src/orchestrator/util.rs
@@ -0,0 +1,38 @@
+//
+// Copyright (c) 2020-2021 science+computing ag and other contributors
+//
+// This program and the accompanying materials are made
+// available under the terms of the Eclipse Public License 2.0
+// which is available at https://www.eclipse.org/legal/epl-2.0/
+//
+// SPDX-License-Identifier: EPL-2.0
+//
+
+use std::collections::HashMap;
+
+use anyhow::Error;
+use uuid::Uuid;
+
+/// Get a `Display`able interface for a Map of errors
+///
+/// This is a helper trait for be able to display a `HashMap<Uuid, Error>`
+/// in a `log::trace!()` call, for example
+pub trait AsReceivedErrorDisplay {
+ fn display_error_map(&self) -> ReceivedErrorDisplay<'_>;
+}
+
+impl AsReceivedErrorDisplay for HashMap<Uuid, Error> {
+ fn display_error_map(&self) -> ReceivedErrorDisplay<'_> {
+ ReceivedErrorDisplay(self)
+ }
+}
+
+
+pub struct ReceivedErrorDisplay<'a>(&'a HashMap<Uuid, Error>);
+
+impl<'a> std::fmt::Display for ReceivedErrorDisplay<'a> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.0.iter().try_for_each(|(uuid, err)| writeln!(f, "{}: {}", uuid, err))
+ }
+}
+