From bab60d38cabc61234ac619d5a5681220dbe43da4 Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Tue, 27 Oct 2020 13:13:19 +0200 Subject: [PATCH] Issue #70 replace `snafu` with `thierror` --- Cargo.toml | 4 +-- src/event/builder.rs | 18 ++++---------- src/message/error.rs | 58 ++++++++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e9cccd06..66b1ec70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ chrono = { version = "^0.4", features = ["serde"] } delegate-attr = "^0.2" base64 = "^0.12" url = { version = "^2.1", features = ["serde"] } -snafu = "^0.6" +thiserror = "^1.0" [target."cfg(not(target_arch = \"wasm32\"))".dependencies] hostname = "^0.3" @@ -48,4 +48,4 @@ exclude = [ "example-projects/actix-web-example", "example-projects/reqwest-wasm-example", "example-projects/rdkafka-example", -] \ No newline at end of file +] diff --git a/src/event/builder.rs b/src/event/builder.rs index ac5927f3..74ed50b5 100644 --- a/src/event/builder.rs +++ b/src/event/builder.rs @@ -1,5 +1,5 @@ use super::Event; -use snafu::Snafu; +use thiserror::Error; /// Trait to implement a builder for [`Event`]: /// ``` @@ -30,24 +30,16 @@ where } /// Represents an error during build process -#[derive(Debug, Snafu, Clone)] +#[derive(Debug, Error, Clone)] pub enum Error { - #[snafu(display("Missing required attribute {}", attribute_name))] + #[error("Missing required attribute {attribute_name}")] MissingRequiredAttribute { attribute_name: &'static str }, - #[snafu(display( - "Error while setting attribute '{}' with timestamp type: {}", - attribute_name, - source - ))] + #[error("Error while setting attribute '{attribute_name}' with timestamp type: {source}")] ParseTimeError { attribute_name: &'static str, source: chrono::ParseError, }, - #[snafu(display( - "Error while setting attribute '{}' with uri/uriref type: {}", - attribute_name, - source - ))] + #[error("Error while setting attribute '{attribute_name}' with uri/uriref type: {source}")] ParseUrlError { attribute_name: &'static str, source: url::ParseError, diff --git a/src/message/error.rs b/src/message/error.rs index 900ae584..d77be5c9 100644 --- a/src/message/error.rs +++ b/src/message/error.rs @@ -1,38 +1,48 @@ -use snafu::Snafu; +use thiserror::Error; /// Represents an error during serialization/deserialization process -#[derive(Debug, Snafu)] +#[derive(Debug, Error)] pub enum Error { - #[snafu(display("Wrong encoding"))] + #[error("Wrong encoding")] WrongEncoding {}, - #[snafu(display("{}", source))] - #[snafu(context(false))] + #[error(transparent)] UnknownSpecVersion { + #[from] source: crate::event::UnknownSpecVersion, }, - #[snafu(display("Unknown attribute in this spec version: {}", name))] + #[error("Unknown attribute in this spec version: {name}")] UnknownAttribute { name: String }, - #[snafu(display("Error while building the final event: {}", source))] - #[snafu(context(false))] + #[error("Error while building the final event: {source}")] EventBuilderError { + #[from] source: crate::event::EventBuilderError, }, - #[snafu(display("Error while parsing a time string: {}", source))] - #[snafu(context(false))] - ParseTimeError { source: chrono::ParseError }, - #[snafu(display("Error while parsing a url: {}", source))] - #[snafu(context(false))] - ParseUrlError { source: url::ParseError }, - #[snafu(display("Error while decoding base64: {}", source))] - #[snafu(context(false))] - Base64DecodingError { source: base64::DecodeError }, - #[snafu(display("Error while serializing/deserializing to json: {}", source))] - #[snafu(context(false))] - SerdeJsonError { source: serde_json::Error }, - #[snafu(display("IO Error: {}", source))] - #[snafu(context(false))] - IOError { source: std::io::Error }, - #[snafu(display("Other error: {}", source))] + #[error("Error while parsing a time string: {source}")] + ParseTimeError { + #[from] + source: chrono::ParseError, + }, + #[error("Error while parsing a url: {source}")] + ParseUrlError { + #[from] + source: url::ParseError, + }, + #[error("Error while decoding base64: {source}")] + Base64DecodingError { + #[from] + source: base64::DecodeError, + }, + #[error("Error while serializing/deserializing to json: {source}")] + SerdeJsonError { + #[from] + source: serde_json::Error, + }, + #[error("IO Error: {source}")] + IOError { + #[from] + source: std::io::Error, + }, + #[error("Other error: {}", source)] Other { source: Box, },