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

Deserialize Extended S3 Errors #429

Merged
merged 11 commits into from
May 28, 2021
Merged

Deserialize Extended S3 Errors #429

merged 11 commits into from
May 28, 2021

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented May 27, 2021

Issue #, if available: Fixes #422
Description of changes: This adds support for deserializing host id from errors for S3.

Semi related changes:

  • fix trailing whitespace that caused cargo fmt to crash
  • add support for AWS-specific inline code
  • fix opaque error when an inline dependency can't be found
  • expose meta() on generated errors
  • add integration test to S3

Example generated code:

pub fn parse_generic_error(
    response: &http::Response<bytes::Bytes>,
) -> Result<smithy_types::Error, smithy_xml::decode::XmlError> {
    let base_err = crate::rest_xml_unwrapped_errors::parse_generic_error(response.body().as_ref())?;
    Ok(crate::s3_errors::parse_extended_error(base_err, &response))
}

The advantage of this style of override is we actually only generating this change in a single place and just invoke this function when deserializing all s3 errors

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rcoh rcoh requested a review from jdisanti May 28, 2021 13:53
@rcoh rcoh changed the title S3 error customizations Deserialize Extended S3 Errors May 28, 2021
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just some minor comments.

error: smithy_types::Error,
response: &http::Response<B>,
) -> smithy_types::Error {
let mut builder = error.into_builder();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor optimization: don't convert into a builder unless you know for certain you have a host_id to add.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converting into a builder will probably just get optimized, it's just a newtype that exposes setters

fn add_error_fields() {
let resp = http::Response::builder()
.header(
"x-amz-id-2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for when the header is missing.

serviceId == ShapeId.from("com.amazonaws.s3#AmazonS3")

override fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap {
val baseProtocols = super.protocols(serviceId, currentProtocols)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is inheriting an interface, there isn't really a super. It has a default implementation, but that just returns currentProtocols. This line doesn't seem necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derp, you are totally right

aws/sdk/integration-tests/s3/Cargo.toml Outdated Show resolved Hide resolved
@jdisanti
Copy link
Collaborator

👍

@rcoh rcoh merged commit a9b6e6e into main May 28, 2021
@rcoh rcoh deleted the s3-error-customizations branch May 28, 2021 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 must also deserialize hostId
2 participants