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

Missing source marker on error throw by vm module with --enable-source-maps #39149

Closed
sonallux opened this issue Jun 25, 2021 · 7 comments
Closed
Labels
confirmed-bug Issues with confirmed bugs. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. source maps Issues and PRs related to source map support.

Comments

@sonallux
Copy link

  • Version: 14.17.0, 16.1.0, 16.4.0 and very likely all between
  • Platform: Microsoft Windows NT 10.0.19042.0 x64
  • Subsystem: vm

What steps will reproduce the bug?

const {Script} = require('vm');
try {
  const script = new Script(`Math.max(a, b`, {filename: 'main'});
} catch (error) {
  console.log(error.stack);
}

Executing the snippet will display the source code line with the marker ^ where the error happened:

main:1
Math.max(a, b
            ^

SyntaxError: missing ) after argument list
    at new Script (vm.js:101:7)
    ...

But when executing node with --enable-source-maps the source code line with the marker is not displayed:

SyntaxError: missing ) after argument list
    at new Script (vm.js:101:7)
    ...

How often does it reproduce? Is there a required condition?

It does always reproduce. I have tested on node 14.17.0, 16.1.0 and 16.4.0.

What is the expected behavior?

Always display the source location with the marker ^ no matter whether --enable-source-maps is set or not.

What do you see instead?

Additional information

On node 14.16.1 the source code line with the marker is always displayed no matter whether --enable-source-maps is set or not. I have looked into the Changelog and I think that maybe #33491 has introduced this bug.

@legendecas legendecas added the source maps Issues and PRs related to source map support. label Jun 25, 2021
@aduh95
Copy link
Contributor

aduh95 commented Jun 25, 2021

@bcoe FYI

@bcoe
Copy link
Contributor

bcoe commented Jun 25, 2021

Prior to #33491 no attempt was made to include a source marker in error output ... so I don't think it introduced the bug, so much as this must be an edge case it doesn't support.

We'll need to dig into this, thanks for the report.

@mediapartners
Copy link

mediapartners commented Mar 19, 2022

@aduh95 @bcoe In case it helps we are having the same problem on v16.14.0 and v14.19.0 however v14.16.0 works correctly. I am able to replicate with just one character.

test.js

{

What is the expected behavior?

>>> node test.js

test.js:1
{
 

SyntaxError: Unexpected end of input
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47

What do you see instead?

>>> node --enable-source-maps test.js

SyntaxError: Unexpected end of input
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47

@bcoe bcoe added the confirmed-bug Issues with confirmed bugs. label Mar 20, 2022
@bcoe
Copy link
Contributor

bcoe commented Mar 20, 2022

We have logic that reads the original source of disk when an error occurs, and uses it to place the source marker, here:

https://github.com/nodejs/node/blob/master/lib/internal/source_map/prepare_stack_trace.js#L173

Will need to dig into if there's way for us to figure out this info in the prepareStackTrace method.

@bcoe bcoe added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Mar 20, 2022
@gabrielcsapo
Copy link

We are seeing this same issue using vm here ember-fastboot/ember-cli-fastboot#894, thanks for the PR @cola119 !

@SebasQuirogaUCP
Copy link

Is still help needed?

@cola119
Copy link
Member

cola119 commented Aug 27, 2022

Fixed in v18.7.0

@cola119 cola119 closed this as completed Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants