Skip to content

Commit cb66180

Browse files
committed
Issue cloudevents#70 replace snafu with thierror
1 parent 39af2d7 commit cb66180

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ chrono = { version = "^0.4", features = ["serde"] }
2323
delegate-attr = "^0.2"
2424
base64 = "^0.12"
2525
url = { version = "^2.1", features = ["serde"] }
26-
snafu = "^0.6"
26+
thiserror = "^1.0"
2727

2828
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
2929
hostname = "^0.3"
@@ -48,4 +48,4 @@ exclude = [
4848
"example-projects/actix-web-example",
4949
"example-projects/reqwest-wasm-example",
5050
"example-projects/rdkafka-example",
51-
]
51+
]

src/event/builder.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Event;
2-
use snafu::Snafu;
2+
use thiserror::Error;
33

44
/// Trait to implement a builder for [`Event`]:
55
/// ```
@@ -30,24 +30,16 @@ where
3030
}
3131

3232
/// Represents an error during build process
33-
#[derive(Debug, Snafu, Clone)]
33+
#[derive(Debug, Error, Clone)]
3434
pub enum Error {
35-
#[snafu(display("Missing required attribute {}", attribute_name))]
35+
#[error("Missing required attribute {attribute_name}")]
3636
MissingRequiredAttribute { attribute_name: &'static str },
37-
#[snafu(display(
38-
"Error while setting attribute '{}' with timestamp type: {}",
39-
attribute_name,
40-
source
41-
))]
37+
#[error("Error while setting attribute '{attribute_name}' with timestamp type: {source}")]
4238
ParseTimeError {
4339
attribute_name: &'static str,
4440
source: chrono::ParseError,
4541
},
46-
#[snafu(display(
47-
"Error while setting attribute '{}' with uri/uriref type: {}",
48-
attribute_name,
49-
source
50-
))]
42+
#[error("Error while setting attribute '{attribute_name}' with uri/uriref type: {source}")]
5143
ParseUrlError {
5244
attribute_name: &'static str,
5345
source: url::ParseError,

src/message/error.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
use snafu::Snafu;
1+
use thiserror::Error;
22

33
/// Represents an error during serialization/deserialization process
4-
#[derive(Debug, Snafu)]
4+
#[derive(Debug, Error)]
55
pub enum Error {
6-
#[snafu(display("Wrong encoding"))]
6+
#[error("Wrong encoding")]
77
WrongEncoding {},
8-
#[snafu(display("{}", source))]
9-
#[snafu(context(false))]
8+
#[error(transparent)]
109
UnknownSpecVersion {
10+
#[from]
1111
source: crate::event::UnknownSpecVersion,
1212
},
13-
#[snafu(display("Unknown attribute in this spec version: {}", name))]
13+
#[error("Unknown attribute in this spec version: {name}")]
1414
UnknownAttribute { name: String },
15-
#[snafu(display("Error while building the final event: {}", source))]
16-
#[snafu(context(false))]
15+
#[error("Error while building the final event: {source}")]
1716
EventBuilderError {
17+
#[from]
1818
source: crate::event::EventBuilderError,
1919
},
20-
#[snafu(display("Error while parsing a time string: {}", source))]
21-
#[snafu(context(false))]
22-
ParseTimeError { source: chrono::ParseError },
23-
#[snafu(display("Error while parsing a url: {}", source))]
24-
#[snafu(context(false))]
25-
ParseUrlError { source: url::ParseError },
26-
#[snafu(display("Error while decoding base64: {}", source))]
27-
#[snafu(context(false))]
28-
Base64DecodingError { source: base64::DecodeError },
29-
#[snafu(display("Error while serializing/deserializing to json: {}", source))]
30-
#[snafu(context(false))]
31-
SerdeJsonError { source: serde_json::Error },
32-
#[snafu(display("IO Error: {}", source))]
33-
#[snafu(context(false))]
34-
IOError { source: std::io::Error },
35-
#[snafu(display("Other error: {}", source))]
20+
#[error("Error while parsing a time string: {source}")]
21+
ParseTimeError { #[from] source: chrono::ParseError },
22+
#[error("Error while parsing a url: {source}")]
23+
ParseUrlError { #[from] source: url::ParseError },
24+
#[error("Error while decoding base64: {source}")]
25+
Base64DecodingError { #[from] source: base64::DecodeError },
26+
#[error("Error while serializing/deserializing to json: {source}")]
27+
SerdeJsonError { #[from] source: serde_json::Error },
28+
#[error("IO Error: {source}")]
29+
IOError { #[from] source: std::io::Error },
30+
#[error("Other error: {}", source)]
3631
Other {
3732
source: Box<dyn std::error::Error + Send + Sync>,
3833
},

0 commit comments

Comments
 (0)