aws-sdk-js-v3: TypeError: Cannot read property 'Code' of undefined

Describe the bug

Periodically, when an SqsClient sends a ReceiveMessageCommand I receive:

TypeError: Cannot read property 'Code' of undefined
    at loadQueryErrorCode (/home/me/node_modules/@aws-sdk/client-sqs/dist/cjs/protocols/Aws_query.js:2583:20)
    at deserializeAws_queryReceiveMessageCommandError (/home/me/node_modules/@aws-sdk/client-sqs/dist/cjs/protocols/Aws_query.js:941:17)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /home/me/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:6:20
    at async /home/me/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:11:20
    at async StandardRetryStrategy.retry (/home/me/node_modules/@aws-sdk/middleware-retry/dist/cjs/StandardRetryStrategy.js:51:46)
    at async /home/me/node_modules/@aws-sdk/middleware-sdk-sqs/dist/cjs/receive-message.js:7:22
    at async /home/me/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22

Your environment

SDK version number

@aws-sdk/client-sqs": "^3.31.0

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

Node.js

Details of the browser/Node.js/ReactNative version

v14.17.5

Steps to reproduce

Please share code or minimal repo, and steps to reproduce the behavior.

      await sqsClient.send(new ReceiveMessageCommand({
        MaxNumberOfMessages: 1,
        QueueUrl: url,
        VisibilityTimeout: 20,
        WaitTimeSeconds: 2,
      }))

Observed behavior

See stack trace above

Expected behavior

Screenshots

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 19
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

bump - same issue, please fix

PR #4367 adds the suggested ?.Code checked access operator. These TypeErrors should now fall through to the default error handler and give more information.

The versioning containing it is https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.261.0

Running into the same error while sending emails with the SES client, the error is masking our efforts to discover the underlying cause.

I also see this issue. I tracked it down to how aws-sdk-v3 is handling error responses from the server. In my case, the server is localstack, if localstack returns an error, aws-sdk-v3 errors on rendering the error, thereby masking the real error.

For example if you try and delete a message on a queue for a message that doesn’t exist, the server responds with something like “invalid receipt handle”, and aws-sdk-v3 insteads shows the Cannot read property 'Code' of undefined error

same issue for me with SES client. Does anyone know any workaround for now? Just want to see what the real issue is (the underlying error messages being masked by this error).

Ran into this as well. Is there a temporary mitigation known?

Happens on 3.41.0, as well.

UPDATE: I fixed the issue i was having. Increasing the WaitTimeSeconds resolved it. I reckon the localstack instance I was running it with, just got overloaded with the new SDK.