diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-03-21 14:19:57 +0100 |
---|---|---|
committer | Marcel Müller <m.mueller@ifm.com> | 2022-03-22 14:16:16 +0100 |
commit | ba67be81e9a1bbbca9bb28ac3abe633aa32492ef (patch) | |
tree | a0ac7d03e09200aeba76d97b2b24f9bc6b17528e /crates | |
parent | 228530e7901f833d1a0066d42c43a01c7c573597 (diff) |
Add dedicated error type for PluginDirectory interface
This patch adds a dedicated error type for the PluginDirectory trait
interface.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/core/tedge_api/examples/heartbeat.rs | 4 | ||||
-rw-r--r-- | crates/core/tedge_api/src/error.rs | 9 | ||||
-rw-r--r-- | crates/core/tedge_api/src/plugin.rs | 4 |
3 files changed, 13 insertions, 4 deletions
diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs index ec12393b..1be5d151 100644 --- a/crates/core/tedge_api/examples/heartbeat.rs +++ b/crates/core/tedge_api/examples/heartbeat.rs @@ -325,7 +325,7 @@ impl PluginDirectory for Communication { fn get_address_for<MB: tedge_api::address::ReceiverBundle>( &self, name: &str, - ) -> Result<Address<MB>, PluginError> { + ) -> Result<Address<MB>, tedge_api::error::DirectoryError> { let types = MB::get_ids().into_iter().collect(); let plug = self.plugins.get(name).unwrap_or_else(|| { @@ -350,7 +350,7 @@ impl PluginDirectory for Communication { } } - fn get_address_for_core(&self) -> Result<Address<tedge_api::CoreMessages>, PluginError> { + fn get_address_for_core(&self) -> Address<tedge_api::CoreMessages> { todo!() } } diff --git a/crates/core/tedge_api/src/error.rs b/crates/core/tedge_api/src/error.rs index 1b4bb99a..9916ea91 100644 --- a/crates/core/tedge_api/src/error.rs +++ b/crates/core/tedge_api/src/error.rs @@ -12,3 +12,12 @@ pub enum PluginError { #[error(transparent)] Custom(#[from] anyhow::Error), } + +#[derive(Error, Debug)] +pub enum DirectoryError { + #[error("Plugin named '{}' not found", .0)] + PluginNameNotFound(String), + + #[error("Plugin '{}' does not support the following message types: {}", .0 ,.1.join(","))] + PluginDoesNotSupport(String, Vec<&'static str>), +} diff --git a/crates/core/tedge_api/src/plugin.rs b/crates/core/tedge_api/src/plugin.rs index bcc9321d..a9b714ca 100644 --- a/crates/core/tedge_api/src/plugin.rs +++ b/crates/core/tedge_api/src/plugin.rs @@ -17,7 +17,7 @@ use async_trait::async_trait; use crate::{ address::{InternalMessage, ReceiverBundle, ReplySender}, - error::PluginError, + error::{PluginError, DirectoryError}, message::CoreMessages, Address, }; @@ -42,7 +42,7 @@ pub trait PluginDirectory: Clone + Send + Sync { /// ## Also see /// /// - [`make_message_bundle`] On how to define your own named message bundle - fn get_address_for<RB: ReceiverBundle>(&self, name: &str) -> Result<Address<RB>, PluginError>; + fn get_address_for<RB: ReceiverBundle>(&self, name: &str) -> Result<Address<RB>, DirectoryError>; /// Request an `Address` to the core itself. It will only accept messages from the /// [`CoreMessages`] bundle. |