Skip to content

error miss filename and line number in 4.x and 5.x when require file compile error #7578

Description

@dead-horse
  • Version: 4.4.7 and 5.12.0
  • Platform: osx

when require a file within a syntax error, the error file name and line number won't set into err.message, but this is fixed in node 6. will we land this fix in node@4 ?

// t.js
try {
  require('./r.js')
} catch (err) {
  console.log(err.stack)
}

// r.js
function // syntax error

in 4 and 5, err.stack will be:

SyntaxError: Unexpected token }
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/deadhorse/git/basement/t.js:2:3)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

in 0.12 and 6, err.stack will be:

/Users/deadhorse/git/basement/r.js:3
});
^
SyntaxError: Unexpected token }
    at Object.exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:513:28)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/deadhorse/git/basement/t.js:2:3)
    at Module._compile (module.js:541:32)

Activity

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

    moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions