aws / aws/aws-sdk-js-codemod

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

Open
#882 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
89
Forks
13
Avg merge
9h 59m
Merged PRs (30d)
1

Description

### 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

```js
import AWS from "aws-sdk";

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

### Observed behavior

```console
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. (/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 ()
at Collection.forEach (/Users/trivikr/.npm/_npx/7c563efbb7515419/node_modules/jscodeshift/dist/Collection.js:74:18)
at NodePath. (/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 ()
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

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

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

### Environment

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

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the S3 request example, then start at removePromiseForCallExpression in transforms/v2-to-v3/apis/removePromiseForCallExpression.js and trace its call from removePromiseCalls.js. The fix is complete when this input no longer raises the undefined length error and produces the expected await request conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.