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

Async SyntaxErrors omit which line the error occurs on #25524

Closed
broofa opened this issue Jan 15, 2019 · 2 comments
Closed

Async SyntaxErrors omit which line the error occurs on #25524

broofa opened this issue Jan 15, 2019 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@broofa
Copy link

broofa commented Jan 15, 2019

  • Version: v11.6.0
  • Platform: Darwin RWK-Mac-2017.local 17.7.0 Darwin Kernel Version 17.7.0: Fri Nov 2 20:43:16 PDT 2018; root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64
  • Subsystem:

Notice in the following two examples, where state is erroneously redeclared, the "Sync Example", provides this (very useful!) information, which is not present in the Async Example:

/Users/kieffer/work/sync_test.js:4
  let state = 123;
      ^

The "first" line of the stack shown in the async example is not the line on which the error occurred. Rather, it is the line that calls the function containing the error. Unfortunately this can be anywhere, so is completely unhelpful in fixing the problem.

Sync Example:

sync_test.js

'use strict';

function foo(state = {}) {
  let state = 123;
}

(function main() {
  foo();
}())
$ node sync_test.js
/Users/kieffer/work/sync_test.js:4
  let state = 123;
      ^

SyntaxError: Identifier 'state' has already been declared
    at main (/Users/kieffer/work/sync_test.js:8:3)
    at Object.<anonymous> (/Users/kieffer/work/sync_test.js:9:2)
(etc...)

Async Example

async_test.js

'use strict';

async function foo(state = {}) {
  let state = 123;
}

(async function main() {
  foo();
}())
$ node async_test.js
(node:89392) UnhandledPromiseRejectionWarning: SyntaxError: Identifier 'state' has already been declared
    at main (/Users/kieffer/work/async_test.js:8:3)
    at Object.<anonymous> (/Users/kieffer/work/async_test.js:9:2)
(etc...)
@devsnek devsnek added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Jan 15, 2019
@devsnek
Copy link
Member

devsnek commented Jan 15, 2019

Duplicate of #11865

@devsnek devsnek marked this as a duplicate of #11865 Jan 15, 2019
@devsnek devsnek closed this as completed Jan 15, 2019
@vsemozhetbyt
Copy link
Contributor

It seems improved in V8 7.3:

>node.12.0.0.v8-7.3.2019-01-02.v8-canary.exe test.js
test.js:4
  let state = 123;
      ^^^^^

SyntaxError: Identifier 'state' has already been declared
    at new Script (vm.js:84:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:312:10)
    at Module._compile (internal/modules/cjs/loader.js:681:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:729:10)
    at Module.load (internal/modules/cjs/loader.js:617:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:771:12)
    at executeUserCode (internal/bootstrap/node.js:434:15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
Projects
None yet
Development

No branches or pull requests

3 participants