Skip to content

awsQueryError trait support #1283

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 2 commits into from
Jun 3, 2021
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
21 changes: 7 additions & 14 deletions codegen/protocol-test-codegen/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.ec2#AwsEc2",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/ec2query"
}
}
},
Expand All @@ -30,8 +29,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.json#JsonProtocol",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc"
}
}
},
Expand All @@ -47,8 +45,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.json10#JsonRpc10",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc10",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/jsonrpc10"
}
}
},
Expand All @@ -64,8 +61,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.query#AwsQuery",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/query"
}
}
},
Expand All @@ -81,8 +77,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.restjson#RestJson",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson"
}
}
},
Expand All @@ -98,8 +93,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.restxml#RestXml",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxml"
}
}
},
Expand All @@ -115,8 +109,7 @@
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.restxml.xmlns#RestXmlWithNamespace",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace",
"moduleVersion": "1.0"
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import static software.amazon.smithy.aws.go.codegen.AwsProtocolUtils.handleDecodeError;
import static software.amazon.smithy.aws.go.codegen.XmlProtocolUtils.initializeXmlDecoder;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait;
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.go.codegen.GoWriter;
Expand All @@ -25,7 +29,6 @@
* Handles generating the aws query protocol for services.
*
* @inheritDoc
*
* @see HttpRpcProtocolGenerator
*/
class AwsQuery extends HttpRpcProtocolGenerator {
Expand Down Expand Up @@ -81,8 +84,8 @@ protected void serializeInputDocument(GenerationContext context, OperationShape

writer.openBlock("if request, err = request.SetStream(bytes.NewReader(bodyWriter.Bytes())); err != nil {",
"}", () -> {
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
writer.write("return out, metadata, &smithy.SerializationError{Err: err}");
});
}

@Override
Expand All @@ -97,7 +100,7 @@ protected void deserializeOutputDocument(GenerationContext context, OperationSha
StructureShape output = ProtocolUtils.expectOutput(context.getModel(), operation);
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
output, context.getService(), getProtocolName());
initializeXmlDecoder(writer, "response.Body", "out, metadata, ","nil");
initializeXmlDecoder(writer, "response.Body", "out, metadata, ", "nil");
unwrapOutputDocument(context, operation);
writer.write("err = $L(&output, decoder)", functionName);
handleDecodeError(writer, "out, metadata, ");
Expand Down Expand Up @@ -152,4 +155,23 @@ protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public Map<String, ShapeId> getOperationErrors(GenerationContext context, OperationShape operation) {
Map<String, ShapeId> errors = new TreeMap<>();

operation.getErrors().forEach(shapeId -> {
Shape errorShape = context.getModel().expectShape(shapeId);
String errorName = shapeId.getName(context.getService());

Optional<AwsQueryErrorTrait> errorShapeTrait = errorShape.getTrait(AwsQueryErrorTrait.class);
if (errorShapeTrait.isPresent()) {
errors.put(errorShapeTrait.get().getCode(), shapeId);
} else {
errors.put(errorName, shapeId);
}
});

return errors;
Comment on lines +161 to +175
Copy link
Contributor

@skotambkar skotambkar Jun 3, 2021

Choose a reason for hiding this comment

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

Should this map key, value pair be reversed?

I would have expected shapeId to be the key, while errorName or code is the value. Is errorName or errorCode guaranteed to be unique within all operation error shapes?

Copy link
Member Author

@skmcgrail skmcgrail Jun 3, 2021

Choose a reason for hiding this comment

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

Error name has to be unique cause it is the shapeId name by default. For query alias’s and whether those conflict that would be a question for smithy on whether they validate that constraint.

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/protocoltest/query/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions service/cloudfront/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions service/cognitoidentityprovider/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions service/elasticache/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions service/elasticbeanstalk/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading