Skip to content

Commit 39af2d7

Browse files
Renamed error variants of message::Error (#90)
* Renamed 2 error variants to be a little bit more consistent (from https://rust-lang.github.io/api-guidelines/naming.html#c-word-order) Signed-off-by: Francesco Guardiani <[email protected]> * message::Error implements Send + Sync Signed-off-by: Francesco Guardiani <[email protected]>
1 parent c926188 commit 39af2d7

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

cloudevents-sdk-rdkafka/src/kafka_producer_record.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl BinarySerializer<MessageRecord> for MessageRecord {
4646
self.headers = self.headers.add(
4747
&headers::ATTRIBUTES_TO_HEADERS
4848
.get(name)
49-
.ok_or(cloudevents::message::Error::UnrecognizedAttributeName {
49+
.ok_or(cloudevents::message::Error::UnknownAttribute {
5050
name: String::from(name),
5151
})?
5252
.clone()[..],

src/event/message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod tests {
122122
#[test]
123123
fn binary_deserializer_unrecognized_attribute_v03() {
124124
assert_eq!(
125-
Error::UnrecognizedAttributeName {
125+
Error::UnknownAttribute {
126126
name: "dataschema".to_string()
127127
}
128128
.to_string(),
@@ -156,7 +156,7 @@ mod tests {
156156
#[test]
157157
fn binary_deserializer_unrecognized_attribute_v10() {
158158
assert_eq!(
159-
Error::UnrecognizedAttributeName {
159+
Error::UnknownAttribute {
160160
name: "schemaurl".to_string()
161161
}
162162
.to_string(),

src/event/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub use event::Event;
1919
pub use extensions::ExtensionValue;
2020
pub(crate) use message::EventBinarySerializer;
2121
pub(crate) use message::EventStructuredSerializer;
22-
pub use spec_version::InvalidSpecVersion;
2322
pub use spec_version::SpecVersion;
23+
pub use spec_version::UnknownSpecVersion;
2424
pub use types::{TryIntoTime, TryIntoUrl};
2525

2626
mod v03;

src/event/spec_version.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ impl fmt::Display for SpecVersion {
4343
}
4444
}
4545

46-
/// Error representing an invalid [`SpecVersion`] string identifier
46+
/// Error representing an unknown [`SpecVersion`] string identifier
4747
#[derive(Debug)]
48-
pub struct InvalidSpecVersion {
48+
pub struct UnknownSpecVersion {
4949
spec_version_value: String,
5050
}
5151

52-
impl fmt::Display for InvalidSpecVersion {
52+
impl fmt::Display for UnknownSpecVersion {
5353
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
5454
write!(f, "Invalid specversion {}", self.spec_version_value)
5555
}
5656
}
5757

58-
impl std::error::Error for InvalidSpecVersion {}
58+
impl std::error::Error for UnknownSpecVersion {}
5959

6060
impl TryFrom<&str> for SpecVersion {
61-
type Error = InvalidSpecVersion;
61+
type Error = UnknownSpecVersion;
6262

63-
fn try_from(value: &str) -> Result<Self, InvalidSpecVersion> {
63+
fn try_from(value: &str) -> Result<Self, UnknownSpecVersion> {
6464
match value {
6565
"0.3" => Ok(SpecVersion::V03),
6666
"1.0" => Ok(SpecVersion::V10),
67-
_ => Err(InvalidSpecVersion {
67+
_ => Err(UnknownSpecVersion {
6868
spec_version_value: value.to_string(),
6969
}),
7070
}

src/event/v03/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl crate::event::message::AttributesSerializer for EventBuilder {
196196
"subject" => self.subject = Some(value.to_string()),
197197
"time" => self.time = Some(value.try_into()?),
198198
_ => {
199-
return Err(crate::message::Error::UnrecognizedAttributeName {
199+
return Err(crate::message::Error::UnknownAttribute {
200200
name: name.to_string(),
201201
})
202202
}

src/event/v10/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl crate::event::message::AttributesSerializer for EventBuilder {
196196
"subject" => self.subject = Some(value.to_string()),
197197
"time" => self.time = Some(value.try_into()?),
198198
_ => {
199-
return Err(crate::message::Error::UnrecognizedAttributeName {
199+
return Err(crate::message::Error::UnknownAttribute {
200200
name: name.to_string(),
201201
})
202202
}

src/message/error.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ pub enum Error {
77
WrongEncoding {},
88
#[snafu(display("{}", source))]
99
#[snafu(context(false))]
10-
InvalidSpecVersion {
11-
source: crate::event::InvalidSpecVersion,
10+
UnknownSpecVersion {
11+
source: crate::event::UnknownSpecVersion,
1212
},
13-
#[snafu(display("Unrecognized attribute name: {}", name))]
14-
UnrecognizedAttributeName { name: String },
13+
#[snafu(display("Unknown attribute in this spec version: {}", name))]
14+
UnknownAttribute { name: String },
1515
#[snafu(display("Error while building the final event: {}", source))]
1616
#[snafu(context(false))]
1717
EventBuilderError {
@@ -33,7 +33,9 @@ pub enum Error {
3333
#[snafu(context(false))]
3434
IOError { source: std::io::Error },
3535
#[snafu(display("Other error: {}", source))]
36-
Other { source: Box<dyn std::error::Error> },
36+
Other {
37+
source: Box<dyn std::error::Error + Send + Sync>,
38+
},
3739
}
3840

3941
/// Result type alias for return values during serialization/deserialization process

0 commit comments

Comments
 (0)