smithy-lang / smithy-typescript

Smithy code generators for TypeScript. (in development)
Apache License 2.0
224 stars 83 forks source link

Mismatch in Error Code Handling in Generated Waiter Functions #1283

Open RanVaknin opened 4 months ago

RanVaknin commented 4 months ago

Issue Description:

There is a discrepancy in how Smithy TypeScript generates waiter functions to handle error codes and their corresponding modeled exceptions. The issue arises because the generated TypeScript code uses the name property of the exception to match errors, but the actual error names returned by AWS differ from the error codes defined in the Smithy model. Root cause is likely that the WaiterGenerator.java code refers to error.name, whereas awsQueryError needs proper matching.

Example

The Smithy model might define an error with the awsQueryError code DBInstanceNotFound, but the actual exception name returned by AWS is DBInstanceNotFoundFault. This leads to incorrect error matching in the generated code, causing waiter functions to either hang indefinitely or fail to transition correctly when the desired resource state is reached.

Smithy model definition:

"com.amazonaws.rds#DBInstanceNotFoundFault": {
  "type": "structure",
  "members": {
    "message": {
      "target": "com.amazonaws.rds#ExceptionMessage"
    }
  },
  "traits": {
    "aws.protocols#awsQueryError": {
      "code": "DBInstanceNotFound",
      "httpResponseCode": 404
    },
    "smithy.api#documentation": "<p>DBInstanceIdentifier doesn't refer to an existing DB instance.</p>",
    "smithy.api#error": "client",
    "smithy.api#httpError": 404
  }
}

Generated TypeScript code:

if (exception.name && exception.name == "DBInstanceNotFound") {
  return { state: "SUCCESS" };
}

Expected Behavior:

The waiter function should correctly recognize the DBInstanceNotFoundFault exception and transition to the success state.

Current Behavior:

The waiter function fails to recognize the DBInstanceNotFoundFault exception, causing it to either hang indefinitely or not transition correctly.

related issue https://github.com/aws/aws-sdk-js-v3/issues/6084