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

Renamed error variants of message::Error #90

Merged
merged 2 commits into from
Oct 21, 2020
Merged
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
2 changes: 1 addition & 1 deletion cloudevents-sdk-rdkafka/src/kafka_producer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl BinarySerializer<MessageRecord> for MessageRecord {
self.headers = self.headers.add(
&headers::ATTRIBUTES_TO_HEADERS
.get(name)
.ok_or(cloudevents::message::Error::UnrecognizedAttributeName {
.ok_or(cloudevents::message::Error::UnknownAttribute {
name: String::from(name),
})?
.clone()[..],
Expand Down
4 changes: 2 additions & 2 deletions src/event/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
#[test]
fn binary_deserializer_unrecognized_attribute_v03() {
assert_eq!(
Error::UnrecognizedAttributeName {
Error::UnknownAttribute {
name: "dataschema".to_string()
}
.to_string(),
Expand Down Expand Up @@ -156,7 +156,7 @@ mod tests {
#[test]
fn binary_deserializer_unrecognized_attribute_v10() {
assert_eq!(
Error::UnrecognizedAttributeName {
Error::UnknownAttribute {
name: "schemaurl".to_string()
}
.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub use event::Event;
pub use extensions::ExtensionValue;
pub(crate) use message::EventBinarySerializer;
pub(crate) use message::EventStructuredSerializer;
pub use spec_version::InvalidSpecVersion;
pub use spec_version::SpecVersion;
pub use spec_version::UnknownSpecVersion;
pub use types::{TryIntoTime, TryIntoUrl};

mod v03;
Expand Down
14 changes: 7 additions & 7 deletions src/event/spec_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ impl fmt::Display for SpecVersion {
}
}

/// Error representing an invalid [`SpecVersion`] string identifier
/// Error representing an unknown [`SpecVersion`] string identifier
#[derive(Debug)]
pub struct InvalidSpecVersion {
pub struct UnknownSpecVersion {
spec_version_value: String,
}

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

impl std::error::Error for InvalidSpecVersion {}
impl std::error::Error for UnknownSpecVersion {}

impl TryFrom<&str> for SpecVersion {
type Error = InvalidSpecVersion;
type Error = UnknownSpecVersion;

fn try_from(value: &str) -> Result<Self, InvalidSpecVersion> {
fn try_from(value: &str) -> Result<Self, UnknownSpecVersion> {
match value {
"0.3" => Ok(SpecVersion::V03),
"1.0" => Ok(SpecVersion::V10),
_ => Err(InvalidSpecVersion {
_ => Err(UnknownSpecVersion {
spec_version_value: value.to_string(),
}),
}
Expand Down
2 changes: 1 addition & 1 deletion src/event/v03/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl crate::event::message::AttributesSerializer for EventBuilder {
"subject" => self.subject = Some(value.to_string()),
"time" => self.time = Some(value.try_into()?),
_ => {
return Err(crate::message::Error::UnrecognizedAttributeName {
return Err(crate::message::Error::UnknownAttribute {
name: name.to_string(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/event/v10/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl crate::event::message::AttributesSerializer for EventBuilder {
"subject" => self.subject = Some(value.to_string()),
"time" => self.time = Some(value.try_into()?),
_ => {
return Err(crate::message::Error::UnrecognizedAttributeName {
return Err(crate::message::Error::UnknownAttribute {
name: name.to_string(),
})
}
Expand Down
12 changes: 7 additions & 5 deletions src/message/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub enum Error {
WrongEncoding {},
#[snafu(display("{}", source))]
#[snafu(context(false))]
InvalidSpecVersion {
source: crate::event::InvalidSpecVersion,
UnknownSpecVersion {
source: crate::event::UnknownSpecVersion,
},
#[snafu(display("Unrecognized attribute name: {}", name))]
UnrecognizedAttributeName { name: String },
#[snafu(display("Unknown attribute in this spec version: {}", name))]
UnknownAttribute { name: String },
#[snafu(display("Error while building the final event: {}", source))]
#[snafu(context(false))]
EventBuilderError {
Expand All @@ -33,7 +33,9 @@ pub enum Error {
#[snafu(context(false))]
IOError { source: std::io::Error },
#[snafu(display("Other error: {}", source))]
Other { source: Box<dyn std::error::Error> },
Other {
source: Box<dyn std::error::Error + Send + Sync>,
},
}

/// Result type alias for return values during serialization/deserialization process
Expand Down