Skip to content
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

fix(version): Fix file formatting on git add #3796

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

BenoitZugmeyer
Copy link
Contributor

@BenoitZugmeyer BenoitZugmeyer commented Jul 27, 2023

Description

PR #3766 brought prettier 3 support by using asynchronous prettier APIs, but missed one await when calling .format(...).

Because of this, fs.writeFileSync(...) is called with a Promise instead of a string and throws an exception:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type
string or an instance of Buffer, > TypedArray, or DataView. Received
an instance of Promise

This exception is caught by the try/catch, and the file is never written.

Worse, when formatting files that are not supported by prettier (ex: yarn.lock), .format(...) fails and the promise rejection isn't handled, which lead to the following exception:

UndefinedParserError: No parser could be inferred for file "..."

and Node terminates the process, which is probably the cause of #3788 and #3773

Motivation and Context

This fixes file formatting and overall crashes during lerna version.

How Has This Been Tested?

Tested when doing a release in a project that uses lerna 7.1.4 and prettier 3.0.0

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (change that has absolutely no effect on users)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR #3766 brought prettier 3 support by using asynchronous prettier APIs,
but missed one `await` when calling `.format(...)`.

Because of this, `fs.writeFileSync(...)` is called with a Promise
instead of a string and throws an exception:

> TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type
> string or an instance of Buffer, > TypedArray, or DataView. Received
> an instance of Promise

This exception is caught by the try/catch, and the file is never
written.

Worse, when formatting files that are not supported by prettier (ex:
yarn.lock), `.format(...)` fails and the promise rejection isn't
handled, which lead to the following exception:

> UndefinedParserError: No parser could be inferred for file "..."

and Node terminates the process, which is probably the cause of #3788
@fahslaj fahslaj merged commit 3123c76 into lerna:main Aug 7, 2023
13 checks passed
@fahslaj
Copy link
Contributor

fahslaj commented Aug 7, 2023

Thank you @BenoitZugmeyer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants