Skip to content

[Bug]: Cannot read properties of undefined error when promise is called on a request #882

@trivikr

Description

@trivikr

Self-service

  • I'd be willing to implement a fix

Describe the bug

Cannot read properties of undefined error when promise is called on a request

Steps to reproduce

import AWS from "aws-sdk";

const client = new AWS.S3({ region: "us-west-2" });
const request = client.listBuckets();
await request.promise();

Observed behavior

TypeError: Cannot read properties of undefined (reading 'length')
    at removePromiseForCallExpression (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/aws-sdk-js-codemod/dist/transforms/v2-to-v3/apis/removePromiseForCallExpression.js:33:47)
    at NodePath.<anonymous> (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/aws-sdk-js-codemod/dist/transforms/v2-to-v3/apis/removePromiseCalls.js:99:85)
    at /Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/jscodeshift/dist/Collection.js:75:36
    at Array.forEach (<anonymous>)
    at Collection.forEach (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/jscodeshift/dist/Collection.js:74:18)
    at NodePath.<anonymous> (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/aws-sdk-js-codemod/dist/transforms/v2-to-v3/apis/removePromiseCalls.js:98:18)
    at /Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/jscodeshift/dist/Collection.js:75:36
    at Array.forEach (<anonymous>)
    at Collection.forEach (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/jscodeshift/dist/Collection.js:74:18)
    at removePromiseCalls (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/aws-sdk-js-codemod/dist/transforms/v2-to-v3/apis/removePromiseCalls.js:86:14)

Expected behavior

import { S3 } from "@aws-sdk/client-s3";

const client = new S3({ region: "us-west-2" });
const request = client.listBuckets();
await request;

Environment

aws-sdk-js-codemod: 2.0.0
- jscodeshift: 0.16.0
- recast: 0.23.9

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions