Node: Illegal continue statement - wrong stack trace with async/await calls

Created on 28 May 2019  路  3Comments  路  Source: nodejs/node

Version: v12.3.1
Platform: Microsoft Windows [Version 10.0.17134.765]

The following SyntaxError provides a wrong stack trace making the error difficult to fix.

async function levelB(){
    // oopsie here (line 3)
    continue;
}

async function levelA(){
    await levelB(); // error trace points here
}

(async () => {
    levelA();
})();
PS S:\...> node .\_bug.js
(node:20028) UnhandledPromiseRejectionWarning: SyntaxError: Illegal continue statement: no surrounding iteration statement
    at levelA (S:\...\_bug.js:7:8)
    at S:\...\_bug.js:11:2
    at Object.<anonymous> (S:\...\_bug.js:12:3)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11
(node:20028) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20028) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The stack trace points at the last await instead of the line where the real error happens. This was caught when re-factoring a larger piece of code and forgetting to replace a continue with return deeper in the code. The wrong syntax occured in a different file, not even mentioned in the stack trace.

Expected output instead: The stack trace should point to line 3, not to line 7.

PS. It is understandable that the error trace points at the async function that failed, but perhaps there should be a better support for SyntaxErrors in async functions?

V8 Engine

Most helpful comment

Yeah. We only find the error when lazily compiling it. I filed a bug in V8.

All 3 comments

I think the main issue here is that the error is emitted at runtime, not at compile time. async function foo() { continue; } seems to compile fine as long as the function isn鈥檛 called.

@nodejs/v8

Yeah. We only find the error when lazily compiling it. I filed a bug in V8.

@addaleax I guess this can be closed since the discussion has moved upstream?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenvachon picture stevenvachon  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

jmichae3 picture jmichae3  路  3Comments

ksushilmaurya picture ksushilmaurya  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments