Skip to content

Commit 3487d94

Browse files
committed
Issue #70 replace snafu with thierror
Signed-off-by: Lachezar Lechev <[email protected]>
1 parent 39af2d7 commit 3487d94

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

Cargo.toml

+2-2
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

+5-13
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

+34-24
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
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 {
22+
#[from]
23+
source: chrono::ParseError,
24+
},
25+
#[error("Error while parsing a url: {source}")]
26+
ParseUrlError {
27+
#[from]
28+
source: url::ParseError,
29+
},
30+
#[error("Error while decoding base64: {source}")]
31+
Base64DecodingError {
32+
#[from]
33+
source: base64::DecodeError,
34+
},
35+
#[error("Error while serializing/deserializing to json: {source}")]
36+
SerdeJsonError {
37+
#[from]
38+
source: serde_json::Error,
39+
},
40+
#[error("IO Error: {source}")]
41+
IOError {
42+
#[from]
43+
source: std::io::Error,
44+
},
45+
#[error("Other error: {}", source)]
3646
Other {
3747
source: Box<dyn std::error::Error + Send + Sync>,
3848
},

0 commit comments

Comments
 (0)