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

fix(codegen): preprocessModel -> map waiter errorType to shapeId if awsQueryError.code #6483

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

RanVaknin
Copy link
Contributor

@RanVaknin RanVaknin commented Sep 17, 2024

This is my most up-to-date attempt at fixing the awsQuery waiter error matcher issue.

In my code, I do 3 things:

  1. Create a key-value store of awsQueryError codes to their corresponding error shape IDs. For example: "LoadBalancerNotFound": "com.amazonaws.elasticloadbalancingv2#LoadBalancerNotFoundException".
    This mapping is used to swap the error matcher.

  2. Traverse down the waiter shapes in the model, moving through the acceptor array → matcher → error type. Once there, I perform the swap in the error matcher to use the correct shape ID.

  3. Track modifications for efficiency to ensure only modified shapes are processed and replaced in the model.

Output:

When I print my changes, I get something promising:

Waitable trait for shape: com.amazonaws.elasticloadbalancingv2#DescribeLoadBalancers
{
    "LoadBalancerAvailable": {
        "acceptors": [
            {
                "state": "success",
                "matcher": {
                    "output": {
                        "path": "LoadBalancers[].State.Code",
                        "expected": "active",
                        "comparator": "allStringEquals"
                    }
                }
            },
            {
                "state": "retry",
                "matcher": {
                    "output": {
                        "path": "LoadBalancers[].State.Code",
                        "expected": "provisioning",
                        "comparator": "anyStringEquals"
                    }
                }
            },
            {
                "state": "retry",
                "matcher": {
                    "errorType": "com.amazonaws.elasticloadbalancingv2#LoadBalancerNotFoundException"
                }
            }
        ],
        "minDelay": 15
    },
"LoadBalancerExists": {...

Issue

When I regenerate the client I see a build error:

Projection elastic-load-balancing-v2.2015-12-01 failed: software.amazon.smithy.model.node.ExpectationNotMetException: Expected shape `com.amazonaws.elasticloadbalancingv2#DescribeLoadBalancers` to have a trait `software.amazon.smithy.waiters.WaitableTrait` (/local/home/rvaknin/workplace/ran/aws-sdk-js-v3/scripts/generate-clients/.aws-models/elastic-load-balancing-v2/elastic-load-balancing-v2.json [2527, 67])
software.amazon.smithy.model.node.ExpectationNotMetException: Expected shape `com.amazonaws.elasticloadbalancingv2#DescribeLoadBalancers` to have a trait `software.amazon.smithy.waiters.WaitableTrait` (/local/home/rvaknin/workplace/ran/aws-sdk-js-v3/scripts/generate-clients/.aws-models/elastic-load-balancing-v2/elastic-load-balancing-v2.json [2527, 67])
	at software.amazon.smithy.model.shapes.Shape.lambda$expectTrait$0(Shape.java:332)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at software.amazon.smithy.model.shapes.Shape.expectTrait(Shape.java:332)
	at software.amazon.smithy.typescript.codegen.DirectedTypeScriptCodegen.generateClient(DirectedTypeScriptCodegen.java:273)
	at software.amazon.smithy.typescript.codegen.DirectedTypeScriptCodegen.generateService(DirectedTypeScriptCodegen.java:176)
	at software.amazon.smithy.codegen.core.directed.CodegenDirector.run(CodegenDirector.java:368)
	at software.amazon.smithy.typescript.codegen.TypeScriptClientCodegenPlugin.execute(TypeScriptClientCodegenPlugin.java:74)
	at software.amazon.smithy.build.SmithyBuildImpl.applyPlugin(SmithyBuildImpl.java:432)
	at software.amazon.smithy.build.SmithyBuildImpl.applyProjection(SmithyBuildImpl.java:364)
	at software.amazon.smithy.build.SmithyBuildImpl.executeSerialProjection(SmithyBuildImpl.java:281)
	at software.amazon.smithy.build.SmithyBuildImpl.lambda$applyAllProjections$4(SmithyBuildImpl.java:201)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
	at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

I also tried changing the mapping from the full shape ID (e.g., "com.amazonaws.elasticloadbalancingv2#LoadBalancerNotFoundException") to just the shape name (e.g., "LoadBalancerNotFoundException"). but that didn't solve the issue.

I suspect I might not be using DynamicTrait correctly.

Copy link
Contributor

@kuhe kuhe left a comment

Choose a reason for hiding this comment

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

We will review collaboratively.

@kuhe kuhe changed the title fix(sdk-codegen): update errorType in waitable traits to use correct … fix(codegen): preprocessModel -> map waiter errorType to shapeId if awsQueryError.code Sep 20, 2024
trivikr and others added 27 commits September 21, 2024 06:05
…role_arn in credential_source (aws#6472)

* fix(credential-provider-ini): fix recursive assume role and optional role_arn in credential_source

* test(credential-provider-ini): fix mock call verification

* test(credential-provider-node): add test case with chained web id token file
…setting for Next.js 14 SSG only applications
…release of Connector for SCEP, a feature of AWS Private CA. Connector for SCEP links your SCEP-enabled and mobile device management systems to AWS Private CA for digital signature installation and certificate management.
…T Device Management Software Package Catalog and Jobs. It also adds SBOM support in Software Package Version.
…PC support to ModelInvocation jobs. To use a cross account bucket, pass in the accountId of the bucket to s3BucketOwner in the ModelInvocationJobInputDataConfig or ModelInvocationJobOutputDataConfig.
…ss-Region organizational units in Automation. Various documentation updates.
…sted GitLab runners in CodeBuild. Add group webhooks
awstools and others added 25 commits September 21, 2024 06:06
… information about the BYOL model for RDS for Db2.
…ailable`, `exploitAvailable`, and `fixedInVersion` fields to provide more detailed information about the availability of fixes, exploits, and fixed versions for identified image vulnerabilities.
* chore(clients): codegen sync for IDE type navigation

* chore: codegen update

* chore: update smithy dependencies
…rchaseRecommendation API to support recommendations for Amazon DynamoDB reservations.
…pgrading snapshots with unsupported engine versions for RDS for MySQL and RDS for PostgreSQL.
…g, and describing access to the AWS Directory Service Data API
…Data API, enabling you to manage data stored in AWS Directory Service directories. This includes APIs for creating, reading, updating, and deleting directory users, groups, and group memberships.
…n, where customers can set up a StringExpression with a MimeHeader condition. This condition will perform the necessary validation based on the X-header provided by customers.
…SageMaker Studio for JupyterLab and CodeEditor applications.
…esource. 2. Commit mode adds visibility configuration of Apply button on multi-select controls for authors.
… and code signing configuration resources.
…al DRM configurations per SPEKE Version 2.0.
… and HEVC encodes, multiplex container settings.
…t field to CreateSyncConfiguration API input, UpdateSyncConfiguration API input, GetSyncConfiguration API output and ListSyncConfiguration API output
…ministrators to view and manage end-user browsing sessions via Session Management APIs.
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.

4 participants