Skip to content

Commit b92df20

Browse files
RanVakninRan Vaknin
andauthored
fix(codegen): preprocess AwsQuery error to shapeId in waiter errorType (#6501)
Co-authored-by: Ran Vaknin <[email protected]>
1 parent c5124c1 commit b92df20

File tree

18 files changed

+113
-16
lines changed

18 files changed

+113
-16
lines changed

clients/client-docdb/src/waiters/waitForDBInstanceDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const checkState = async (client: DocDBClient, input: DescribeDBInstancesCommand
8383
} catch (e) {}
8484
} catch (exception) {
8585
reason = exception;
86-
if (exception.name && exception.name == "DBInstanceNotFound") {
86+
if (exception.name && exception.name == "DBInstanceNotFoundFault") {
8787
return { state: WaiterState.SUCCESS, reason };
8888
}
8989
}

clients/client-elastic-load-balancing-v2/src/waiters/waitForLoadBalancerAvailable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const checkState = async (
4747
} catch (e) {}
4848
} catch (exception) {
4949
reason = exception;
50-
if (exception.name && exception.name == "LoadBalancerNotFound") {
50+
if (exception.name && exception.name == "LoadBalancerNotFoundException") {
5151
return { state: WaiterState.RETRY, reason };
5252
}
5353
}

clients/client-elastic-load-balancing-v2/src/waiters/waitForLoadBalancerExists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const checkState = async (
1818
return { state: WaiterState.SUCCESS, reason };
1919
} catch (exception) {
2020
reason = exception;
21-
if (exception.name && exception.name == "LoadBalancerNotFound") {
21+
if (exception.name && exception.name == "LoadBalancerNotFoundException") {
2222
return { state: WaiterState.RETRY, reason };
2323
}
2424
}

clients/client-elastic-load-balancing-v2/src/waiters/waitForLoadBalancersDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const checkState = async (
3333
} catch (e) {}
3434
} catch (exception) {
3535
reason = exception;
36-
if (exception.name && exception.name == "LoadBalancerNotFound") {
36+
if (exception.name && exception.name == "LoadBalancerNotFoundException") {
3737
return { state: WaiterState.SUCCESS, reason };
3838
}
3939
}

clients/client-elastic-load-balancing-v2/src/waiters/waitForTargetDeregistered.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const checkState = async (
3030
} catch (e) {}
3131
} catch (exception) {
3232
reason = exception;
33-
if (exception.name && exception.name == "InvalidTarget") {
33+
if (exception.name && exception.name == "InvalidTargetException") {
3434
return { state: WaiterState.SUCCESS, reason };
3535
}
3636
}

clients/client-elastic-load-balancing/src/waiters/waitForInstanceDeregistered.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const checkState = async (
3333
} catch (e) {}
3434
} catch (exception) {
3535
reason = exception;
36-
if (exception.name && exception.name == "InvalidInstance") {
36+
if (exception.name && exception.name == "InvalidEndPointException") {
3737
return { state: WaiterState.SUCCESS, reason };
3838
}
3939
}

clients/client-elastic-load-balancing/src/waiters/waitForInstanceInService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const checkState = async (
3333
} catch (e) {}
3434
} catch (exception) {
3535
reason = exception;
36-
if (exception.name && exception.name == "InvalidInstance") {
36+
if (exception.name && exception.name == "InvalidEndPointException") {
3737
return { state: WaiterState.RETRY, reason };
3838
}
3939
}

clients/client-elasticache/src/waiters/waitForCacheClusterDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const checkState = async (
117117
} catch (e) {}
118118
} catch (exception) {
119119
reason = exception;
120-
if (exception.name && exception.name == "CacheClusterNotFound") {
120+
if (exception.name && exception.name == "CacheClusterNotFoundFault") {
121121
return { state: WaiterState.SUCCESS, reason };
122122
}
123123
}

clients/client-iam/src/waiters/waitForPolicyExists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const checkState = async (client: IAMClient, input: GetPolicyCommandInput): Prom
1212
return { state: WaiterState.SUCCESS, reason };
1313
} catch (exception) {
1414
reason = exception;
15-
if (exception.name && exception.name == "NoSuchEntity") {
15+
if (exception.name && exception.name == "NoSuchEntityException") {
1616
return { state: WaiterState.RETRY, reason };
1717
}
1818
}

clients/client-iam/src/waiters/waitForRoleExists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const checkState = async (client: IAMClient, input: GetRoleCommandInput): Promis
1212
return { state: WaiterState.SUCCESS, reason };
1313
} catch (exception) {
1414
reason = exception;
15-
if (exception.name && exception.name == "NoSuchEntity") {
15+
if (exception.name && exception.name == "NoSuchEntityException") {
1616
return { state: WaiterState.RETRY, reason };
1717
}
1818
}

clients/client-iam/src/waiters/waitForUserExists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const checkState = async (client: IAMClient, input: GetUserCommandInput): Promis
1212
return { state: WaiterState.SUCCESS, reason };
1313
} catch (exception) {
1414
reason = exception;
15-
if (exception.name && exception.name == "NoSuchEntity") {
15+
if (exception.name && exception.name == "NoSuchEntityException") {
1616
return { state: WaiterState.RETRY, reason };
1717
}
1818
}

clients/client-neptune/src/waiters/waitForDBInstanceDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const checkState = async (client: NeptuneClient, input: DescribeDBInstancesComma
8383
} catch (e) {}
8484
} catch (exception) {
8585
reason = exception;
86-
if (exception.name && exception.name == "DBInstanceNotFound") {
86+
if (exception.name && exception.name == "DBInstanceNotFoundFault") {
8787
return { state: WaiterState.SUCCESS, reason };
8888
}
8989
}

clients/client-rds/src/waiters/waitForDBInstanceDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const checkState = async (client: RDSClient, input: DescribeDBInstancesCommandIn
7575
} catch (e) {}
7676
} catch (exception) {
7777
reason = exception;
78-
if (exception.name && exception.name == "DBInstanceNotFound") {
78+
if (exception.name && exception.name == "DBInstanceNotFoundFault") {
7979
return { state: WaiterState.SUCCESS, reason };
8080
}
8181
}

clients/client-rds/src/waiters/waitForDBSnapshotDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const checkState = async (client: RDSClient, input: DescribeDBSnapshotsCommandIn
7575
} catch (e) {}
7676
} catch (exception) {
7777
reason = exception;
78-
if (exception.name && exception.name == "DBSnapshotNotFound") {
78+
if (exception.name && exception.name == "DBSnapshotNotFoundFault") {
7979
return { state: WaiterState.SUCCESS, reason };
8080
}
8181
}

clients/client-redshift/src/waiters/waitForClusterAvailable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const checkState = async (client: RedshiftClient, input: DescribeClustersCommand
4141
} catch (e) {}
4242
} catch (exception) {
4343
reason = exception;
44-
if (exception.name && exception.name == "ClusterNotFound") {
44+
if (exception.name && exception.name == "ClusterNotFoundFault") {
4545
return { state: WaiterState.RETRY, reason };
4646
}
4747
}

clients/client-redshift/src/waiters/waitForClusterDeleted.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const checkState = async (client: RedshiftClient, input: DescribeClustersCommand
3939
} catch (e) {}
4040
} catch (exception) {
4141
reason = exception;
42-
if (exception.name && exception.name == "ClusterNotFound") {
42+
if (exception.name && exception.name == "ClusterNotFoundFault") {
4343
return { state: WaiterState.SUCCESS, reason };
4444
}
4545
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.aws.typescript.codegen;
7+
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait;
13+
import software.amazon.smithy.model.Model;
14+
import software.amazon.smithy.model.knowledge.TopDownIndex;
15+
import software.amazon.smithy.model.node.ObjectNode;
16+
import software.amazon.smithy.model.shapes.OperationShape;
17+
import software.amazon.smithy.model.shapes.ServiceShape;
18+
import software.amazon.smithy.model.shapes.Shape;
19+
import software.amazon.smithy.model.shapes.ShapeId;
20+
import software.amazon.smithy.model.traits.ErrorTrait;
21+
import software.amazon.smithy.model.transform.ModelTransformer;
22+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
23+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
24+
import software.amazon.smithy.utils.SmithyInternalApi;
25+
import software.amazon.smithy.waiters.Acceptor;
26+
import software.amazon.smithy.waiters.Matcher;
27+
import software.amazon.smithy.waiters.WaitableTrait;
28+
import software.amazon.smithy.waiters.Waiter;
29+
30+
31+
@SmithyInternalApi
32+
public final class ProcessAwsQueryWaiters implements TypeScriptIntegration {
33+
34+
@Override
35+
public Model preprocessModel(Model model, TypeScriptSettings settings) {
36+
Map<String, String> errorCodeToShapeId = new HashMap<>();
37+
38+
ServiceShape serviceShape = settings.getService(model);
39+
TopDownIndex topDownIndex = TopDownIndex.of(model);
40+
for (OperationShape operationShape : topDownIndex.getContainedOperations(serviceShape)) {
41+
for (ShapeId errorShapeId : operationShape.getErrors()) {
42+
Shape errorShape = model.expectShape(errorShapeId);
43+
if (errorShape.hasTrait(ErrorTrait.class) && errorShape.hasTrait(AwsQueryErrorTrait.class)) {
44+
AwsQueryErrorTrait awsQueryTrait = errorShape.expectTrait(AwsQueryErrorTrait.class);
45+
errorCodeToShapeId.put(awsQueryTrait.getCode(), errorShape.getId().getName());
46+
}
47+
}
48+
}
49+
50+
List<Shape> modifiedShapes = new ArrayList<>();
51+
52+
for (OperationShape operationShape : topDownIndex.getContainedOperations(serviceShape)) {
53+
OperationShape.Builder operationBuilder = operationShape.toBuilder();
54+
if (operationShape.hasTrait(WaitableTrait.class)) {
55+
operationBuilder.removeTrait(WaitableTrait.ID);
56+
WaitableTrait waiterTrait = operationShape.expectTrait(WaitableTrait.class);
57+
WaitableTrait.Builder waitableTraitBuilder = (WaitableTrait.Builder) waiterTrait.toBuilder();
58+
for (Map.Entry<String, Waiter> entry : waiterTrait.getWaiters().entrySet()) {
59+
String name = entry.getKey();
60+
Waiter waiter = entry.getValue();
61+
Waiter.Builder waiterBuilder = (Waiter.Builder) waiter.toBuilder();
62+
waiterBuilder.clearAcceptors();
63+
for (Acceptor acceptor : waiter.getAcceptors()) {
64+
ObjectNode acceptorNode = acceptor.toNode().expectObjectNode();
65+
Matcher matcher = acceptor.getMatcher();
66+
if (matcher instanceof Matcher.ErrorTypeMember) {
67+
ObjectNode matcherNode = matcher.toNode().expectObjectNode();
68+
69+
String errorCode = matcherNode.expectStringMember("errorType").getValue();
70+
if (errorCodeToShapeId.containsKey(errorCode)) {
71+
matcherNode = matcherNode.toBuilder()
72+
.withMember("errorType", errorCodeToShapeId.get(errorCode))
73+
.build();
74+
75+
acceptorNode = acceptorNode.toBuilder()
76+
.withMember("matcher", matcherNode)
77+
.build();
78+
}
79+
}
80+
waiterBuilder.addAcceptor(Acceptor.fromNode(acceptorNode));
81+
}
82+
waitableTraitBuilder.put(name, waiterBuilder.build());
83+
}
84+
operationBuilder.addTrait(waitableTraitBuilder.build());
85+
}
86+
modifiedShapes.add(operationBuilder.build());
87+
}
88+
89+
if (!modifiedShapes.isEmpty()) {
90+
ModelTransformer transformer = ModelTransformer.create();
91+
model = transformer.replaceShapes(model, modifiedShapes);
92+
}
93+
94+
return model;
95+
}
96+
}

codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ software.amazon.smithy.aws.typescript.codegen.AddDocumentClientPlugin
2727
software.amazon.smithy.aws.typescript.codegen.AddEndpointDiscoveryPlugin
2828
software.amazon.smithy.aws.typescript.codegen.AddHttpChecksumDependency
2929
software.amazon.smithy.aws.typescript.codegen.AddSigv4aPlugin
30+
software.amazon.smithy.aws.typescript.codegen.ProcessAwsQueryWaiters
3031
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustomizeHttpBearerTokenAuth
3132
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.SupportSigV4Auth
3233
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustomizeSigV4Auth

0 commit comments

Comments
 (0)