create-strapi-app doesn't await writing license.txt, so a failed write skips its error handling

Open Beginner friendly
#28,637 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
playwright, typescript
Domain
cli, testing

Research direction

Start with the growth SSO trial block in packages/cli/create-strapi-app/src/create-strapi.ts, around lines 176-186, and add await to the fse.writeFile call for license.txt. Then check the four unawaited calls in tests/e2e/tests: clickLoginTimes in admin/login.spec.ts, previousVersion.click in content-manager/history.spec.ts, and titleBox.fill in content-manager/preview.spec.ts. Done when every one of these promises is awaited and the affected create-strapi-app and e2e tests still pass.

Written by the indexing model from the issue text.

Description

flag: invalid template issue: bug severity: low source: cli status: pending reproduction version: 5
Node Version

Any (found in the code)

Package Manager

Any

Package Manager Version

Any

Strapi Version

develop at 6ed1be0

Operating System

Any

Database

Any

Javascript or Typescript

TypeScript

Bug Description

In create-strapi.ts, the growth SSO trial license is written without await:

https://github.com/strapi/strapi/blob/6ed1be0fd1a0d37f25a0e0a74ecac2bebb9f14f3/packages/cli/create-strapi-app/src/create-strapi.ts#L176-L186

try {
  const data = await createGrowthSsoTrial({ strapiVersion: scope.strapiVersion });

  if (data?.license) {
    fse.writeFile(join(rootPath, 'license.txt'), data.license);
    logger.log('Your 30 days trial will be applied automatically to your project. Enjoy!');
  }
} catch {
  logger.error('Error while trying to create your trial. Please try again later.');
}

Because the promise isn't awaited, the catch never sees a failed write, and the success message is logged before the file exists. If the write fails, the rejection is unhandled, and since Node 15 that ends the process partway through creating the project instead of logging the error and carrying on. The other writes in the same function (.env on line 158, .yarnrc.yml on 164, .gitignore on 227) are awaited.

A failed write here should be rare, so this is a small one, but the fix is one word.

Steps to Reproduce

I haven't run this end to end; it follows from the code. To see it, make that one write fail (for example, stub fse.writeFile to reject for license.txt) and create a project with the trial:

  1. Run create-strapi-app with shouldCreateGrowthSsoTrial on.
  2. The license write rejects.
  3. The process exits with an unhandled rejection instead of logging "Error while trying to create your trial".
Expected Behavior

await fse.writeFile(join(rootPath, 'license.txt'), data.license);, so a failed write reaches the catch, and the message is logged only once the file is written.

Code Snippets

The same missing await is in four e2e tests. Playwright's next expect usually waits long enough for these to work, but a test can end before the action does, and an action that fails becomes an unhandled rejection rather than a failed step:

Each of these calls is awaited elsewhere in the same file.

Additional information

Found with Stratum Open's check for promises left unawaited.

Dominant language
TypeScript
Stars
73.5k
Forks
10k
Avg merge
3d 11h
Merged PRs (30d)
276

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from strapi/strapi

All issues in strapi/strapi

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.