diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-09-15 08:47:26 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-09-15 08:47:26 +0200 |
commit | 43ec1a6e3618db0c35970b6eddb87a4e83c8b622 (patch) | |
tree | 305652252f51c7c981d56d93cfca06fba634dd7a | |
parent | 08a32f3294d65b4011e54838fc67c792cf8f3ff0 (diff) |
Handle lifecycle errors at plugin startup
This patch adds lifecycle-error handling during startup time.
If one plugin errors during start, the application does not start.
One might argue that we should shutdown the other plugins that
successfully started. This is not implemented in this patch.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r-- | crates/core/tedge_core/src/reactor.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/crates/core/tedge_core/src/reactor.rs b/crates/core/tedge_core/src/reactor.rs index 07d06c01..3c4e6a91 100644 --- a/crates/core/tedge_core/src/reactor.rs +++ b/crates/core/tedge_core/src/reactor.rs @@ -181,10 +181,8 @@ impl Reactor { }) .collect(); - // TODO: Handle these errors - debug!("Running 'start' for plugins"); - let _start_results = all_plugins + let (_start_results_ok, start_results_err): (Vec<_>, Vec<_>) = all_plugins .iter_mut() .map(|plugin_task| { let span = @@ -194,7 +192,15 @@ impl Reactor { .collect::<futures::stream::FuturesOrdered<_>>() .collect::<Vec<Result<(), _>>>() .instrument(tracing::info_span!("core.mainloop.plugins.start")) - .await; + .await + .into_iter() + .partition_result(); + + if !start_results_err.is_empty() { + return Err(TedgeApplicationError::PluginLifecycleErrors { + errors: start_results_err, + }); + } debug!("Enabling communications for plugins"); all_plugins |