diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-04-22 11:13:23 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-05-02 10:16:35 +0200 |
commit | 1dbc2287b0c155b3c3375361e517137996158a5d (patch) | |
tree | b7843f54db6cebf7b16c19681a6a7604e0a8e3f2 /plugins/plugin_measurement_filter | |
parent | 0c46da47d4a33081b5c4e34ebf9554d23e1f0d97 (diff) |
plugin_measurement_filter: Improve error reporting
This patch improves the error handling story of the
plugin_measurement_filter by introducing a dedicated error type.
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'plugins/plugin_measurement_filter')
-rw-r--r-- | plugins/plugin_measurement_filter/Cargo.toml | 2 | ||||
-rw-r--r-- | plugins/plugin_measurement_filter/src/builder.rs | 4 | ||||
-rw-r--r-- | plugins/plugin_measurement_filter/src/error.rs | 5 | ||||
-rw-r--r-- | plugins/plugin_measurement_filter/src/lib.rs | 1 |
4 files changed, 10 insertions, 2 deletions
diff --git a/plugins/plugin_measurement_filter/Cargo.toml b/plugins/plugin_measurement_filter/Cargo.toml index bb80818d..fa894bad 100644 --- a/plugins/plugin_measurement_filter/Cargo.toml +++ b/plugins/plugin_measurement_filter/Cargo.toml @@ -13,6 +13,8 @@ serde = { version = "1", features = ["derive"] } serde_with = "1.12" tokio = { version = "1", features = ["rt"] } tokio-util = "0.7.0" +thiserror = "1" +toml = "0.5" tedge_api = { path = "../../crates/core/tedge_api" } tedge_lib = { path = "../../crates/core/tedge_lib" } diff --git a/plugins/plugin_measurement_filter/src/builder.rs b/plugins/plugin_measurement_filter/src/builder.rs index 05b7e369..24f55759 100644 --- a/plugins/plugin_measurement_filter/src/builder.rs +++ b/plugins/plugin_measurement_filter/src/builder.rs @@ -41,7 +41,7 @@ where .clone() .try_into() .map(|_: MeasurementFilterConfig| ()) - .map_err(|_| miette::miette!("Failed to parse filter configuration")) + .map_err(crate::error::Error::from) .map_err(PluginError::from) } @@ -53,7 +53,7 @@ where ) -> Result<BuiltPlugin, PluginError> { let config = config .try_into::<MeasurementFilterConfig>() - .map_err(|_| miette::miette!("Failed to parse filter configuration"))?; + .map_err(crate::error::Error::from)?; let main_addr = plugin_dir.get_address_for(&config.target)?; let filtered_addr = config diff --git a/plugins/plugin_measurement_filter/src/error.rs b/plugins/plugin_measurement_filter/src/error.rs new file mode 100644 index 00000000..5b7f977a --- /dev/null +++ b/plugins/plugin_measurement_filter/src/error.rs @@ -0,0 +1,5 @@ +#[derive(Debug, miette::Diagnostic, thiserror::Error)] +pub(crate) enum Error { + #[error("Failed to parse configuration")] + ConfigParseFailed(#[from] toml::de::Error), +} diff --git a/plugins/plugin_measurement_filter/src/lib.rs b/plugins/plugin_measurement_filter/src/lib.rs index 95bd51e3..2d74d0d5 100644 --- a/plugins/plugin_measurement_filter/src/lib.rs +++ b/plugins/plugin_measurement_filter/src/lib.rs @@ -1,5 +1,6 @@ mod builder; mod config; +mod error; mod extractor; mod filter; mod plugin; |