Skip to content

Error objects are different in v2 and v3 #759

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

Closed
trivikr opened this issue Jan 20, 2020 · 3 comments
Closed

Error objects are different in v2 and v3 #759

trivikr opened this issue Jan 20, 2020 · 3 comments
Labels
bug This issue is a bug. smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch

Comments

@trivikr
Copy link
Member

trivikr commented Jan 20, 2020

Describe the bug
Error objects are different in v2 and v3

SDK version number

$ npm list aws-sdk
└── [email protected]
$ npm list @aws-sdk/client-cloudtrail
└── @aws-sdk/[email protected]

Is the issue in the browser/Node.js?
Node.js

Details of the browser/Node.js version

$ node -v
v12.14.0

To Reproduce (observed behavior)
Reproduced using the following code:

const AWS = require("aws-sdk");
const { CloudTrail } = require("@aws-sdk/client-cloudtrail");

(async () => {
  const v2Client = new AWS.CloudTrail();

  try {
    await v2Client.createTrail({}).promise();
  } catch (e) {
    console.log("\nError returned by v2:");
    console.log(JSON.stringify(e, null, 2));
  }

  const v3Client = new CloudTrail({});

  try {
    // Try to reate trail with invalid name
    await v3Client.createTrail({});
  } catch (e) {
    console.log("\nError returned by v3:");
    console.log(JSON.stringify(e, null, 2));
  }
})();

Output:

Error returned by v2:
{
  "message": "There were 2 validation errors:\n* MissingRequiredParameter: Missing required key 'Name' in params\n* MissingRequiredParameter: Missing required key 'S3BucketName' in params",
  "code": "MultipleValidationErrors",
  "errors": [
    {
      "message": "Missing required key 'Name' in params",
      "code": "MissingRequiredParameter",
      "time": "2020-01-20T18:42:30.422Z"
    },
    {
      "message": "Missing required key 'S3BucketName' in params",
      "code": "MissingRequiredParameter",
      "time": "2020-01-20T18:42:30.422Z"
    }
  ],
  "time": "2020-01-20T18:42:30.422Z"
}

Error returned by v3:
{
  "name": "InvalidTrailNameException",
  "__type": "InvalidTrailNameException",
  "$fault": "client",
  "$metadata": {
    "httpStatusCode": 400,
    "httpHeaders": {
      "x-amzn-requestid": "a0ef2a90-7167-4a8d-9624-a30e4f3e0729",
      "content-type": "application/x-amz-json-1.1",
      "content-length": "78",
      "date": "Mon, 20 Jan 2020 18:44:29 GMT",
      "connection": "close"
    },
    "requestId": "a0ef2a90-7167-4a8d-9624-a30e4f3e0729",
    "retries": 0,
    "totalRetryDelay": 0
  },
  "Message": "Trail name cannot be blank!"
}

Expected behavior
Creating this issue for documenting Expected behavior

@trivikr trivikr added third-party This issue is related to third-party libraries or applications. bug This issue is a bug. smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch and removed third-party This issue is related to third-party libraries or applications. labels Jan 20, 2020
@trivikr
Copy link
Member Author

trivikr commented Jan 20, 2020

Differences:

  • v2 error object contains message in key "message" while v3 error object contains message in "Message"
    • suggestion: use "message" as that is used by JavaScript error constructor (MDN)
  • v2 error object documents all validation errors with code "MultipleValidationErrors" while v3 error object documents only first error "InvalidTrailNameException"
    • suggestion: Throw all validation errors at once, so users can fix all of them at once.

trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Jan 20, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Jan 22, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Jan 23, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Jan 29, 2020
@kstich
Copy link
Contributor

kstich commented Jan 30, 2020

The error difference described is an intended difference in SDK versions - v2 here performed client side validation (throwing this exception code explicitly here) and v3 does not. This results in v3 sending the request and receiving the error shown above, and is an intentional improvement.

Closing this as the remaining issue in it is a duplicate of the more clearly described #763.

@kstich kstich closed this as completed Jan 30, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Jan 31, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this issue Feb 4, 2020
@lock
Copy link

lock bot commented Feb 6, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. smithy-codegen Changes regarding supporting smithy model. Will be merged to smithy-codegen branch
Projects
None yet
Development

No branches or pull requests

2 participants