Skip to content

Commit

Permalink
Issue cloudevents#70 replace snafu with thierror
Browse files Browse the repository at this point in the history
  • Loading branch information
elpiel committed Oct 27, 2020
1 parent 39af2d7 commit bab60d3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
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
58 changes: 34 additions & 24 deletions src/message/error.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error + Send + Sync>,
},
Expand Down

0 comments on commit bab60d3

Please sign in to comment.