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: gRPC await promise transpilation, bump ECMAScript target to ES2018 #689

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

kon14
Copy link
Contributor

@kon14 kon14 commented Sep 25, 2023

This PR resolves a huge bug around await usage in gRPC handlers being incorrectly transpiled into yield outside generators.

Example (a section of Database module's createView() gRPC handler):

try {
    await this._activeAdapter.createView(
        call.request.schemaName,
        call.request.viewName,
        call.request.joinedSchemas,
        call.request.query,
    );
        callback(null);
    } 

This should in theory transpile into code that only executes the callback after the promise has returned.
Alas we got this:

try {
    yield this._activeAdapter.createView(call.request.schemaName, call.request.viewName, call.request.joinedSchemas, call.request.query);
    callback(null); // @dirty-type-cast
}

Modifying the original TypeScript code so that the callback would execute inside a .then() instead of after an await successfully resulted in this:

try {
    this._activeAdapter.createView(call.request.schemaName, call.request.viewName, call.request.joinedSchemas, call.request.query)
        .then(() => callback(null));
}

But that solution seems like a huge step backwards in terms of readability and would otherwise result in an error-prone codebase.
Thankfully, this bug seems to be resolved in recent ES targets, where await is natively supported.
The actual issue is probably related to TypeScript#6242, although in my tests ES6 wasn't enough.

We could technically bump everything except for the libraries all the way up to es2022 without requiring a Ts or Node container image bump, but I decided to stick with ES2018 across the board for now.

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other (please describe)

Does this PR introduce a breaking change?

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the main branch
  • When resolving a specific issue, it's referenced in the PR's description (e.g. fix #xxx, where "xxx" is the issue number)

@ghost
Copy link

ghost commented Sep 25, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@kkopanidis kkopanidis merged commit 8058195 into main Sep 25, 2023
4 checks passed
@kkopanidis kkopanidis deleted the bump-es branch September 25, 2023 11:57
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