-
Notifications
You must be signed in to change notification settings - Fork 597
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
s3-client generates uncatchable error on bad Body
type
#4848
Comments
Body
typeBody
type
Hi @rafak , Unfortunately I'm not able to reproduce the reported behavior. My application logs the error from the context of the catch block: const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')
const send = async () => {
try {
const client = new S3Client({
region: "us-east-1",
credentials: {
"accessKeyId": "Foo",
"secretAccessKey": "Bar",
}})
const command = new PutObjectCommand({
Bucket:'testbucket-3650', Key: 'testing-sdk', Body: {}
})
const result = await client.send(command)
return result
} catch (err) {
console.error('GOT ERROR', err)
throw err
}
}
send() Dockerfile: FROM node:16.20.0
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["node", "sample.js"] $ docker build -t 4848 .
$ docker run -it --rm 4848
node:internal/errors:478
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object
at new NodeError (node:internal/errors:387:5)
at Function.from (node:buffer:328:9)
at writeBody (/app/node_modules/@aws-sdk/node-http-handler/dist-cjs/write-request-body.js:40:32)
at writeRequestBody (/app/node_modules/@aws-sdk/node-http-handler/dist-cjs/write-request-body.js:31:9)
at async resolve (/app/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js:55:17) {
code: 'ERR_INVALID_ARG_TYPE'
} I noticed that you are using both async await and .then().catch() which is the syntax for promises. While I'm not sure if this is the source of the issue, I would just choose one or the other. See my code example for how I would write make this call. If you can give my implementation a try and let me know how it goes. Otherwise can you provide a github repository with minimal code required to consistently reproduce this issue? Thank you very much, |
i see the error but i don't see the "GOT ERROR" from the the
but that does not change much anyway based on your code i would expect your snippet to produce output along the lines:
|
how about if you swallow the error?
will there be any output on the console? |
@RanVaknin the file (x.js):
execution:
would you agree that the error should not be output to the console if it was caught by the |
Thanks for the clarification. I see what you are saying. Added this to our queue. Thanks, |
should be fixed in releases including the not yet created https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.360.0, the next expected release is on Monday. |
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. |
Checkboxes for prior research
Describe the bug
when using
client-s3/PutObjectCommand
with a badBody
type, an uncatchableTypeError
is thrownSDK version number
@aws-sdk/client-s3: ^3.352.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v16.20.0
Reproduction Steps
dependencies:
@aws-sdk/client-s3
version^3.352.0
running the following inside a docker container:
file
x.js
execute:
Observed Behavior
using and empty object (
{}
) as the input parameterBody
to thePutObjectCommand
creates and uncaught exception.the error was not caught in the
try-catch
blockthe exception was caught on the process level:
process.on('uncaughtException', (...))
Expected Behavior
i expected the aws-sdk to validate the input and throw an error early
i expected the error to be caught in the
catch (err) {}
block of theasync send() {}
functionPossible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: