diff options
-rw-r--r-- | Cargo.lock | 25 | ||||
-rw-r--r-- | crates/core/tedge_api/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/core/tedge_api/examples/heartbeat.rs | 9 | ||||
-rw-r--r-- | crates/core/tedge_api/src/error.rs | 18 |
4 files changed, 36 insertions, 18 deletions
@@ -1323,6 +1323,29 @@ dependencies = [ ] [[package]] +name = "miette" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a097de91d72c13382f60213ed9f7f7a26afd8bee0ea320b47f886a9a67ca5a1" +dependencies = [ + "miette-derive", + "once_cell", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette-derive" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a95a48d0bc28f9af628286e8a4da09f96f34a97744a2e9a5a4db9814ad527d" +dependencies = [ + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", +] + +[[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2696,10 +2719,10 @@ dependencies = [ name = "tedge_api" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "downcast-rs", "futures", + "miette", "serde", "static_assertions", "thiserror", diff --git a/crates/core/tedge_api/Cargo.toml b/crates/core/tedge_api/Cargo.toml index 28163849..afcd9800 100644 --- a/crates/core/tedge_api/Cargo.toml +++ b/crates/core/tedge_api/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1.0.53" async-trait = "0.1.52" downcast-rs = "1.2.0" futures = "0.3.21" +miette = "4.4.0" thiserror = "1.0.30" tokio = { version = "1.16.1", features = ["sync", "time"] } tokio-util = "0.7.0" diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs index 35ac183d..8806e726 100644 --- a/crates/core/tedge_api/examples/heartbeat.rs +++ b/crates/core/tedge_api/examples/heartbeat.rs @@ -35,6 +35,12 @@ impl Message for HeartbeatStatus { #[derive(Debug)] struct HeartbeatServiceBuilder; +#[derive(miette::Diagnostic, thiserror::Error, Debug)] +enum HeartbeatBuildError { + #[error(transparent)] + TomlParse(#[from] toml::de::Error), +} + #[async_trait] impl<PD: PluginDirectory> PluginBuilder<PD> for HeartbeatServiceBuilder { fn kind_name() -> &'static str { @@ -64,7 +70,8 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for HeartbeatServiceBuilder { where PD: 'async_trait, { - let hb_config: HeartbeatConfig = toml::Value::try_into(config)?; + let hb_config: HeartbeatConfig = + toml::Value::try_into(config).map_err(HeartbeatBuildError::from)?; let monitored_services = hb_config .plugins .iter() diff --git a/crates/core/tedge_api/src/error.rs b/crates/core/tedge_api/src/error.rs index 76c96368..a84110fd 100644 --- a/crates/core/tedge_api/src/error.rs +++ b/crates/core/tedge_api/src/error.rs @@ -1,21 +1,9 @@ +use miette::Diagnostic; use thiserror::Error; -/// An error that a plugin might emit -#[derive(Error, Debug)] -pub enum PluginError { - /// Error kind if the configuration of the plugin was faulty - #[error("An error in the configuration was found")] - Configuration(#[from] toml::de::Error), +pub type PluginError = miette::Report; - /// Error kind to report any `anyhow::Error` error - #[error(transparent)] - Custom(#[from] anyhow::Error), - - #[error("Error from directory")] - DirectoryError(#[from] DirectoryError), -} - -#[derive(Error, Debug)] +#[derive(Error, Debug, Diagnostic)] pub enum DirectoryError { #[error("Plugin named '{}' not found", .0)] PluginNameNotFound(String), |