Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

vm.createScript a better error info #5677

Closed
orenz opened this issue Jun 12, 2013 · 4 comments
Closed

vm.createScript a better error info #5677

orenz opened this issue Jun 12, 2013 · 4 comments

Comments

@orenz
Copy link

orenz commented Jun 12, 2013

It would be nice to have a line number. If your script is getting longer, it's really hard to find what is wrong.

@bnoordhuis
Copy link
Member

It's a V8 limitation. It doesn't give useful stack traces on syntax errors.

There's a crude (and undocumented) hack to get the line number.

var source = Array(42).join('\n') + '0x';
var NodeScript = process.binding('evals').NodeScript;
new NodeScript(source, 'fail.js', true);

Prints:

fail.js:42
0x
^^
SyntaxError: Unexpected token ILLEGAL
    at [eval]:1:59
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:449:26)
    at evalScript (node.js:459:25)
    at startup (node.js:80:7)
    at node.js:828:3

I'll see if we can improve this somehow.

@orenz
Copy link
Author

orenz commented Jun 12, 2013

Thanks !

On Wed, Jun 12, 2013 at 11:36 PM, Ben Noordhuis [email protected]:

It's a V8 limitation. It doesn't give useful stack traces on syntax errors.

There's a crude (and undocumented) hack to get the line number.

var source = Array(42).join('\n') + '0x';var NodeScript = process.binding('evals').NodeScript;new NodeScript(source, 'fail.js', true);

Prints:

fail.js:42
0x
^^
SyntaxError: Unexpected token ILLEGAL
at [eval]:1:59
at Object. ([eval]-wrapper:6:22)
at Module._compile (module.js:449:26)
at evalScript (node.js:459:25)
at startup (node.js:80:7)
at node.js:828:3

I'll see if we can improve this somehow.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5677#issuecomment-19353697
.

@bnoordhuis
Copy link
Member

Closing, this works reasonably well now with the latest V8:

> vm.runInThisContext('true \n false \n if (0 ?= 0)', 'x.js')

x.js:3
if(0 ?= 0) 0
      ^
SyntaxError: Unexpected token =
    at Object.exports.runInThisContext (vm.js:69:16)
    at repl:1:4

@qraynaud
Copy link

Which version of V8/node do we need to use to get such a nice output ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants