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

[Bug]: promise is never resolved in case of using await in if block inside of catch #109

Closed
le0nik opened this issue Apr 28, 2018 · 5 comments

Comments

@le0nik
Copy link

le0nik commented Apr 28, 2018

fast-async@6.3.6
nodent-transform@3.2.3
nodent-compiler@3.2.2

async function test() {
    try {
        await Promise.reject(new Error('err'));
    } catch (error) {
        if (true) {
            await Promise.resolve();
        }
    } finally {
        console.log('finally');
    }
}

The problem is in an if block inside of catch. It generates an empty try {} catch ($boundEx) inside of $Try_1_Catch which results in $Try_1_Finally never being called and promise never being resolved.

Line 22 here:
http://nodent.mailed.me.uk/#async%20function%20test()%20%7B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20await%20Promise.reject(new%20Error('err'))%3B%0A%20%20%20%20%7D%20catch%20(error)%20%7B%0A%20%20%20%20%20%20%20%20if%20(true)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20Promise.resolve()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20finally%20%7B%0A%20%20%20%20%20%20%20%20console.log('finally')%3B%0A%20%20%20%20%7D%0A%7D%0A%0Atest()%3B~options~%7B%22mode%22%3A%22promises%22%2C%22promiseType%22%3A%22native%22%2C%22noRuntime%22%3Atrue%2C%22es6target%22%3Atrue%2C%22wrapAwait%22%3Afalse%2C%22spec%22%3Afalse%7D

If you run this code finally block is never reached

@le0nik le0nik changed the title [Bug]: empty try block is generated instead of calling Try_Finally inside of if block in catch [Bug]: promise is never resolved in case of using await in if block inside of catch Apr 28, 2018
@le0nik
Copy link
Author

le0nik commented Apr 28, 2018

It started happening after updating nodent-compiler from 3.1.8 to 3.2.2. Pinning nodent-compiler's version back to 3.1.8 in package-lock.json solves the problem.

Just in case i've also pinned fast-async version to 6.3.4 in package.json because it depends on nodent-compiler@^3.2.2.

@MatAtBread
Copy link
Owner

Thanks for the report. I'll try and work out why this regression happens.

@MatAtBread
Copy link
Owner

Quick update: this issue is block-nesting. If you remove the block enclosing the if body, it works. I have an idea why this might have occurred, I just need to add it to my test cases and find a fix(!)

MatAtBread added a commit to MatAtBread/nodent-compiler that referenced this issue Apr 30, 2018
MatAtBread added a commit that referenced this issue Apr 30, 2018
- Fix issue where `catch` body was incompletely transformed (see
#109)

- Fix issue where unreachable continuation generated an illegal
Identifer after try-catch (see
MatAtBread/fast-async#56)
@le0nik
Copy link
Author

le0nik commented Apr 30, 2018

Thx. Can confirm that it's working correctly now.

@MatAtBread
Copy link
Owner

You're welcome - thanks for the report and test case

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

No branches or pull requests

2 participants