Skip to content

Support modeled exceptions in event streams #655

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

Merged
merged 1 commit into from
Aug 11, 2018

Conversation

varunnvs92
Copy link
Contributor

  • Add support for modeled exceptions in event streams
  • Fix bug in AddExceptionShapes class where we only generate exceptions declared in operations. But event shapes can have modeled exceptions as members.

@varunnvs92 varunnvs92 requested a review from shorea August 10, 2018 08:40
@@ -46,28 +44,21 @@
// Java shape models, to be constructed
final Map<String, ShapeModel> javaShapes = new HashMap<String, ShapeModel>();

for (Map.Entry<String, Operation> entry : getServiceModel().getOperations().entrySet()) {
for (Map.Entry<String, Shape> shape : getServiceModel().getShapes().entrySet()) {
if (shape.getValue().isException()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will be okay to do but you may want to validate this by importing the Dev preview package to see if any unexpected source changes occur in the generated client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I validated the shape names but makes sense to review the entire generated code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I verified that there is no diff in the generated code.

Throwable exception = exceptionUnmarshaller.handle(adaptMessageToResponse(m, true),
EMPTY_EXECUTION_ATTRIBUTES);
SdkHttpFullResponse errorResponse = adaptMessageToResponse(m, true);
if (!errorResponse.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).isPresent() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can omit the first part of the conditional. The error response shouldn't have a request id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I was thinking in case the format changes in future. Will update

import software.amazon.awssdk.core.runtime.transform.Unmarshaller;

@SdkProtectedApi
public class EventStreamExceptionJsonUnmarshaller<T extends AwsServiceException>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep this around for backwards compat and add a ReviewBeforeRelease so we only make a breaking change once at full GA?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

return null;
}

if (filteredHeaders.size() > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the customer experience in this situation? We generally try to be as resilient as possible when unmarshlaling the exceptions so we can preserve as much info as possible about the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you saying we should combine all the error codes? I think its confusing if service multiple headers representing the error code with different values. If they do, maybe we can select the first option and return it? what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever we do we should try to fail as gracefully a possible so that we still generate a service exception rather than a runtime one. I'm thinking selecting the first one we find and log a warning.

assertThat(e.statusCode()).isEqualTo(500);
assertThat(e.awsErrorDetails().errorCode()).isEqualTo(errorCode);
assertThat(e.awsErrorDetails().errorMessage()).isEqualTo("foo");
assertThat(e.awsErrorDetails().serviceName()).isEqualTo("kinesis");
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this value come from? Is it unique?

Copy link
Contributor Author

@varunnvs92 varunnvs92 Aug 10, 2018

Choose a reason for hiding this comment

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

It comes from the service name generated in the client interface

Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm I don't think we should be using that value as it's not very unique and for some services it's vague like 'execute-api'. I'll create a issue in our backlog to address this as it's not related to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove the change to populate the service name then

Copy link
Contributor

Choose a reason for hiding this comment

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

You can leave it in if you want. We are already exposing it for normal exceptions so we'll have to figure out the best way forward regardless.

@varunnvs92 varunnvs92 force-pushed the varunkn/EventStreamModeledExceptions branch from 2a4c6e9 to c996f7c Compare August 10, 2018 20:59
@varunnvs92 varunnvs92 force-pushed the varunkn/EventStreamModeledExceptions branch from c996f7c to bd96ba9 Compare August 10, 2018 21:46
@shorea shorea merged commit 8cb9942 into master Aug 11, 2018
@varunnvs92 varunnvs92 deleted the varunkn/EventStreamModeledExceptions branch August 11, 2018 09:17
aws-sdk-java-automation pushed a commit that referenced this pull request Oct 31, 2019
…55dea7e4

Pull request: release <- staging/d4ff341a-63a3-4ef2-9a90-e1f455dea7e4
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.

2 participants