Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace snafu with thiserror #93

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -48,4 +48,4 @@ exclude = [
"example-projects/actix-web-example",
"example-projects/reqwest-wasm-example",
"example-projects/rdkafka-example",
]
]
18 changes: 5 additions & 13 deletions src/event/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Event;
use snafu::Snafu;
use thiserror::Error;

/// Trait to implement a builder for [`Event`]:
/// ```
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
//! * [cloudevents-sdk-reqwest](https://docs.rs/cloudevents-sdk-reqwest): Integration with [reqwest](https://github.com/seanmonstar/reqwest)
//!

extern crate serde;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for extern crate in the 2018 edition

extern crate serde_json;
extern crate serde_value;
extern crate snafu;

/// Provides [`Event`] data structure, [`EventBuilder`] and other facilities to work with [`Event`]
pub mod event;
/// Provides facilities to implement Protocol Bindings
Expand Down
59 changes: 35 additions & 24 deletions src/message/error.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
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)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will handle the impl of Display to the underlying error.

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 {
#[from]
source: Box<dyn std::error::Error + Send + Sync>,
elpiel marked this conversation as resolved.
Show resolved Hide resolved
},
}
Expand Down