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

errors: strange position name in error stack #15386

Closed
vsemozhetbyt opened this issue Sep 13, 2017 · 13 comments
Closed

errors: strange position name in error stack #15386

vsemozhetbyt opened this issue Sep 13, 2017 · 13 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Sep 13, 2017

  • Version: 8.5.0, master (9.0.0 2017 09 12)
  • Platform: Windows 7 x64
  • Subsystem: errors

Compare these 3 async IIFEs and their error stacks (different code lines and corresponded stack position names are marked by // NB string):

'use strict';

function promiseFunc(arg) {
  return new Promise(function promiseHandlers(resolve, reject) {
    if (arg) resolve(`Got ${arg}`);
    else reject(new Error(`Got ${arg}`));
  });
}

(async function asyncFunc() {                // NB
  try {
    const result = await promiseFunc(true);
    console.log(`Result: ${result}`);

    await promiseFunc(false);
    console.log('This is not logged.');
  } catch (err) {
    console.error(err);
  }
}());

(async function () {                         // NB
  try {
    const result = await promiseFunc(true);
    console.log(`Result: ${result}`);

    await promiseFunc(false);
    console.log('This is not logged.');
  } catch (err) {
    console.error(err);
  }
}());

(async () => {                               // NB
  try {
    const result = await promiseFunc(true);
    console.log(`Result: ${result}`);

    await promiseFunc(false);
    console.log('This is not logged.');
  } catch (err) {
    console.error(err);
  }
})();
Result: Got true
Result: Got true
Result: Got true
Error: Got false
    at promiseHandlers (e:\DOC\prg\js\node\-test\test.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (e:\DOC\prg\js\node\-test\test.js:4:10)
    at asyncFunc (e:\DOC\prg\js\node\-test\test.js:15:11)                // NB
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3
Error: Got false
    at promiseHandlers (e:\DOC\prg\js\node\-test\test.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (e:\DOC\prg\js\node\-test\test.js:4:10)
    at e:\DOC\prg\js\node\-test\test.js:27:11                            // NB
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3
Error: Got false
    at promiseHandlers (e:\DOC\prg\js\node\-test\test.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (e:\DOC\prg\js\node\-test\test.js:4:10)
    at __dirname (e:\DOC\prg\js\node\-test\test.js:39:11)                // NB
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:201:16)
    at bootstrap_node.js:626:3

Is __dirname position name in the last stack intended?

@vsemozhetbyt vsemozhetbyt added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Sep 13, 2017
@targos
Copy link
Member

targos commented Sep 13, 2017

I think it's a bug. Here is the output with d8:

Result: Got true
Result: Got true
Result: Got true
Error: Got false
    at promiseHandlers (/home/mzasso/test/stack.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (/home/mzasso/test/stack.js:4:10)
    at asyncFunc (/home/mzasso/test/stack.js:15:11)
    at <anonymous>
Error: Got false
    at promiseHandlers (/home/mzasso/test/stack.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (/home/mzasso/test/stack.js:4:10)
    at /home/mzasso/test/stack.js:27:11
    at <anonymous>
Error: Got false
    at promiseHandlers (/home/mzasso/test/stack.js:6:17)
    at Promise (<anonymous>)
    at promiseFunc (/home/mzasso/test/stack.js:4:10)
    at /home/mzasso/test/stack.js:39:11
    at <anonymous>

@targos targos added the v8 engine Issues and PRs related to the V8 dependency. label Sep 13, 2017
@targos
Copy link
Member

targos commented Sep 13, 2017

OK this is a V8 bug. Repro for d8:

(function (param1) {

  (async () => {
    try {
      await Promise.reject(new Error('boom'));
    } catch (err) {
      console.error(err.stack);
    }
  })();

})();
Error: boom
    at param1 (problem.js:5:28)
    at problem.js:9:5
    at problem.js:11:3

/cc @nodejs/v8

@targos
Copy link
Member

targos commented Sep 13, 2017

It does not have to be an async function btw:

(function (param1) {

  (() => {
    try {
      throw new Error('boom');
    } catch (err) {
      console.error(err.stack);
    }
  })();

})();
Error: boom
    at param1 (problem.js:5:13)
    at problem.js:9:5
    at problem.js:11:3

@vsemozhetbyt
Copy link
Contributor Author

@targos So is the output in the OP somehow connected with module wrapper last argument?

@targos
Copy link
Member

targos commented Sep 13, 2017

Exactly. The bug is that the stack trace uses the name of the last argument of the outer function in place of the name of the function, when that function is a arrow function.

@vsemozhetbyt
Copy link
Contributor Author

@targos Do you plan to post upstream or should I try to?

@targos
Copy link
Member

targos commented Sep 13, 2017

@vsemozhetbyt
Copy link
Contributor Author

Hopefully done. Should we close this issue or should it remain open till upstream fix?

@targos
Copy link
Member

targos commented Sep 13, 2017

Let's keep it open until we know if the fix can be backported

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Sep 13, 2017

FWIW, the output from maintained branches (Node.js v6 with v8 5.1 seems concerned in a different way):

'use strict';

(function (param1) {

  (() => {
    try {
      throw new Error('boom');
    } catch (err) {
      console.error(err.stack);
    }
  })();

})();
> node.4.8.4.v8-4.5.exe test.js
Error: boom
    at e:\DOC\prg\js\node\-test\test.js:7:13
    at e:\DOC\prg\js\node\-test\test.js:11:5
    at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:13:3)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3

> node.6.11.3.v8-5.1.exe test.js
Error: boom
    at err (e:\DOC\prg\js\node\-test\test.js:7:13)
    at e:\DOC\prg\js\node\-test\test.js:11:5
    at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:13:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)

> node.8.5.0.v8-6.0.exe test.js
Error: boom
    at param1 (e:\DOC\prg\js\node\-test\test.js:7:13)
    at e:\DOC\prg\js\node\-test\test.js:11:5
    at Object.<anonymous> (e:\DOC\prg\js\node\-test\test.js:13:3)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)

@mscdex mscdex removed the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Sep 13, 2017
@targos
Copy link
Member

targos commented Nov 24, 2017

This was fixed in https://chromium-review.googlesource.com/c/v8/v8/+/742657
I guess we can safely backport this commit.

@tuomassalo
Copy link

Any idea on which Node.js version(s) this will be included in?

(I apologize if that's something I should have known how to google.)

targos added a commit to targos/node that referenced this issue Jan 9, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

Refs: v8/v8@c3458a8
Closes: nodejs#15386
@targos
Copy link
Member

targos commented Jan 9, 2018

I think nobody opened a backport PR yet. I just did for 8.x and 9.x:
#18059
#18060

targos added a commit that referenced this issue Jan 11, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#49042}

PR-URL: #18060
Fixes: #15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
targos added a commit to targos/node that referenced this issue Jan 15, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#18060
Fixes: nodejs#15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
gibfahn pushed a commit to gibfahn/node that referenced this issue Jan 16, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#16413
Fixes: nodejs#15386
Refs: v8/v8@c3458a8
gibfahn pushed a commit to gibfahn/node that referenced this issue Jan 16, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#18060
Backport-PR-URL: nodejs#16413
Fixes: nodejs#15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
gibfahn pushed a commit to gibfahn/node that referenced this issue Jan 22, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#16413
Refs: v8/v8@c3458a8
Closes: nodejs#15386
gibfahn pushed a commit to gibfahn/node that referenced this issue Jan 22, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#18060
Backport-PR-URL: nodejs#16413
Fixes: nodejs#15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 7, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#49042}

PR-URL: #18059
Closes: #15386
Fixes: #15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit to targos/node that referenced this issue Feb 7, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{nodejs#49042}

PR-URL: nodejs#18060
Fixes: nodejs#15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
gibfahn pushed a commit that referenced this issue Feb 18, 2018
Original commit message:

    [parser] Add new FunctionNameInferrer state before parsing param

    Create new state before parsing FormalParameter because we don't
    want to use any of the parameters as an inferred function name.

    Previously the stacktrace was:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at param (test.js:3:11)
          at test.js:4:5
          at test.js:6:3

    The stacktrace with this patch:
      test.js:3: Error: boom
          throw new Error('boom');
          ^
      Error: boom
          at test.js:3:11
          at test.js:4:5
          at test.js:6:3

    Bug: v8:6822, v8:6513
    Change-Id: Ifbadc660fc4e85248af405acd67c025f11662bd4
    Reviewed-on: https://chromium-review.googlesource.com/742657
    Reviewed-by: Adam Klein <adamk@chromium.org>
    Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#49042}

PR-URL: #18060
Backport-PR-URL: #16413
Fixes: #15386
Refs: v8/v8@c3458a8
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@targos targos closed this as completed Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

4 participants