summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMarcel Müller <m.mueller@ifm.com>2022-04-13 10:35:18 +0200
committerMarcel Müller <m.mueller@ifm.com>2022-04-13 10:35:18 +0200
commit9ccd86589db8f9a72c4d7f545813e8da40b4d039 (patch)
treec65b0798fd53d65b1b914602ead0dcb1dc68cd33 /crates
parentcb823b72c1c64646db4cbc4d4631b9d3885efb3c (diff)
Replace PluginError with miette::Error
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/core/tedge_api/Cargo.toml2
-rw-r--r--crates/core/tedge_api/examples/heartbeat.rs9
-rw-r--r--crates/core/tedge_api/src/error.rs18
3 files changed, 12 insertions, 17 deletions
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),