aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.96k stars 557 forks source link

`ValidationError` should report the error fields starting from upper case that matches the command's input type #6109

Closed riywo closed 1 month ago

riywo commented 1 month ago

Describe the feature

SDK returns ValidationError but its message reports the error fields starting from lower case (in the example below, it's accessKeyId, not AccessKeyId):

import { STSClient, GetAccessKeyInfoCommand } from "@aws-sdk/client-sts";

const client = new STSClient();
// const command = new GetAccessKeyInfoCommand({ AccessKeyId: "..." });  <= Proper input
const command = new GetAccessKeyInfoCommand();  // <= Wrong input
await client.send(command);
STSServiceException [ValidationError]: 1 validation error detected: Value null at 'accessKeyId' failed to satisfy constraint: Member must not be null

Use Case

This is a bit confusing. While TypeScript doesn't allow lower case fields, JavaScript users might face bugs due to such typo if they just copy & paste from the error message.

Proposed Solution

Returning the error fields starting from upper case that matches the command's input type.

Other Information

No response

Acknowledgements

SDK version used

3.577.0

Environment details (OS name and version, etc.)

Linux d7be8a114a11 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux

RanVaknin commented 1 month ago

Hi @riywo ,

The error you are seeing is a server side error thrown by the STS service itself. The types that the SDK generates are in upper case because they reflect STS's credentials object described here which models each fields as uppercase.

Since all of the AWS SDKs are code generated from the API model of each AWS service, the SDK team cannot edit those types. Additionally, editing the types to be lower case would be a backwards incompatible change and not something that we can support.

If you are looking for an ease of use solution, you can use any modern IDE's intellisense to help you fill in the correct parameter name:

image

Since this feature is not actionable by the SDK team, I'm going to go ahead and close this.

Thanks, Ran~

github-actions[bot] commented 3 weeks ago

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.