Skip to content

Commit

Permalink
Fix CI failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Oct 18, 2022
1 parent 756035e commit c450949
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class EventStreamUnmarshallerGenerator(
}
rustBlock("value => ") {
rustTemplate(
"return Err(#{Error}::Unmarshalling(format!(\"unrecognized :message-type: {}\", value)));",
"return Err(#{Error}::unmarshalling(format!(\"unrecognized :message-type: {}\", value)));",
*codegenScope,
)
}
Expand Down Expand Up @@ -156,7 +156,7 @@ class EventStreamUnmarshallerGenerator(
*codegenScope,
)
false -> rustTemplate(
"return Err(#{Error}::Unmarshalling(format!(\"unrecognized :event-type: {}\", _unknown_variant)));",
"return Err(#{Error}::unmarshalling(format!(\"unrecognized :event-type: {}\", _unknown_variant)));",
*codegenScope,
)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ class EventStreamUnmarshallerGenerator(
"""
let content_type = response_headers.content_type().unwrap_or_default();
if content_type != ${contentType.dq()} {
return Err(#{Error}::Unmarshalling(format!(
return Err(#{Error}::unmarshalling(format!(
"expected :content-type to be '$contentType', but was '{}'",
content_type
)))
Expand All @@ -269,7 +269,7 @@ class EventStreamUnmarshallerGenerator(
rustTemplate(
"""
std::str::from_utf8(message.payload())
.map_err(|_| #{Error}::Unmarshalling("message payload is not valid UTF-8".into()))?
.map_err(|_| #{Error}::unmarshalling("message payload is not valid UTF-8"))?
""",
*codegenScope,
)
Expand All @@ -288,7 +288,7 @@ class EventStreamUnmarshallerGenerator(
"""
#{parser}(&message.payload()[..])
.map_err(|err| {
#{Error}::Unmarshalling(format!("failed to unmarshall $memberName: {}", err))
#{Error}::unmarshalling(format!("failed to unmarshall $memberName: {}", err))
})?
""",
"parser" to parser,
Expand Down Expand Up @@ -336,7 +336,7 @@ class EventStreamUnmarshallerGenerator(
"""
builder = #{parser}(&message.payload()[..], builder)
.map_err(|err| {
#{Error}::Unmarshalling(format!("failed to unmarshall ${member.memberName}: {}", err))
#{Error}::unmarshalling(format!("failed to unmarshall ${member.memberName}: {}", err))
})?;
return Ok(#{UnmarshalledMessage}::Error(
#{OpError}::new(
Expand All @@ -360,7 +360,7 @@ class EventStreamUnmarshallerGenerator(
"""
builder = #{parser}(&message.payload()[..], builder)
.map_err(|err| {
#{Error}::Unmarshalling(format!("failed to unmarshall ${member.memberName}: {}", err))
#{Error}::unmarshalling(format!("failed to unmarshall ${member.memberName}: {}", err))
})?;
""",
"parser" to parser,
Expand Down Expand Up @@ -394,7 +394,7 @@ class EventStreamUnmarshallerGenerator(
CodegenTarget.SERVER -> {
rustTemplate(
"""
return Err(aws_smithy_eventstream::error::Error::Unmarshalling(
return Err(aws_smithy_eventstream::error::Error::unmarshalling(
format!("unrecognized exception: {}", response_headers.smithy_type.as_str()),
));
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class EventStreamErrorMarshallerGenerator(
rustTemplate(
"""
$errorName::Unhandled(_inner) => return Err(
#{Error}::Marshalling(${unknownVariantError(unionSymbol.rustType().name).dq()}.to_owned())
#{Error}::marshalling(${unknownVariantError(unionSymbol.rustType().name).dq()}.to_owned())
),
""",
*codegenScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class EventStreamMarshallerGenerator(
rustTemplate(
"""
Self::Input::${UnionGenerator.UnknownVariantName} => return Err(
#{Error}::Marshalling(${unknownVariantError(unionSymbol.rustType().name).dq()}.to_owned())
#{Error}::marshalling(${unknownVariantError(unionSymbol.rustType().name).dq()}.to_owned())
)
""",
*codegenScope,
Expand Down Expand Up @@ -211,7 +211,7 @@ open class EventStreamMarshallerGenerator(
rustTemplate(
"""
#{serializerFn}(&$input)
.map_err(|err| #{Error}::Marshalling(format!("{}", err)))?
.map_err(|err| #{Error}::marshalling(format!("{}", err)))?
""",
"serializerFn" to serializerFn,
*codegenScope,
Expand Down
16 changes: 16 additions & 0 deletions rust-runtime/aws-smithy-eventstream/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) enum ErrorKind {
PayloadTooLong,
PreludeChecksumMismatch(u32, u32),
TimestampValueTooLarge(DateTime),
Marshalling(String),
Unmarshalling(String),
}

Expand All @@ -36,6 +37,20 @@ impl Error {
pub(crate) fn kind(&self) -> &ErrorKind {
&self.kind
}

/// Create an `Error` for failure to marshall a message from a Smithy shape
pub fn marshalling(message: impl Into<String>) -> Self {
Self {
kind: ErrorKind::Marshalling(message.into()),
}
}

/// Create an `Error` for failure to unmarshall a message into a Smithy shape
pub fn unmarshalling(message: impl Into<String>) -> Self {
Self {
kind: ErrorKind::Unmarshalling(message.into()),
}
}
}

impl From<ErrorKind> for Error {
Expand Down Expand Up @@ -75,6 +90,7 @@ impl fmt::Display for Error {
"timestamp value {:?} is too large to fit into an i64",
time
),
Marshalling(error) => write!(f, "failed to marshall message: {}", error),
Unmarshalling(error) => write!(f, "failed to unmarshall message: {}", error),
}
}
Expand Down

0 comments on commit c450949

Please sign in to comment.