镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@sonallux
  • 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.

Activity

  1. aduh95 commented on Jun 25, 2021

    @aduh95
    Contributor

    @bcoe FYI

  2. bcoe commented on Jun 25, 2021

    @bcoe
    Contributor

    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.

  3. mediapartners commented on Mar 19, 2022

    @mediapartners

    @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
    
  4. bcoe commented on Mar 20, 2022

    @bcoe
    Contributor

    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.

  5. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Mar 20, 2022
  6. gabrielcsapo commented on Jun 13, 2022

    @gabrielcsapo

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

  7. SebasQuirogaUCP commented on Aug 26, 2022

    @SebasQuirogaUCP

    Is still help needed?

  8. cola119 commented on Aug 27, 2022

    @cola119
    Member

    Fixed in v18.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.source mapsIssues and PRs related to source map support.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions