Repository navigation
require(): no information about where error #3784
Description
Activity
- addedmoduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
on Nov 12, 2015 you should be able to run
node -c <file>to do a syntax check.Reacted by Ethan Yang@amurchick I believe this is specific to REPL. Can you please confirm if my understanding is correct?
It is REPL specific.
Looking into it a bit, the difference between
requireing the file and loading it directly is interesting.
Therequireflow goes through loading the file and then callingnode::ContextifyScript::New(vm.js, node_contextify.cc) which propagates theSyntaxErrorto the javascript-land caller.On the other hand, towards the end of the regular load's flow
node::ReportExceptionis called, which prints the origin of the exception from a hidden value:arrow = err_obj->GetHiddenValue(env->arrow_message_string());The naive first thought will be to call
ReportExceptioninContextifyScript::New, but that means the error will be printed even when the exception is caught.
The better second thought will be to expose the currently hidden value on the error object, but that'll single out node as the only environment to have this behaviour.
The even better third thought will be to exposeReportExceptionas a binding, and havereplcall that on uncaught exceptions. That'll not only solve this issue, but also give more detailed errors on regular errors, which may or may not be desirable.Thoughts?
@thefourtheye @cjihrig - it is NOT REPL specific. Try this:
$ node -v v5.0.0 $ cat test.js try { var a = require('./auth'); } catch (e) { console.error(e.stack); } $ cat auth.js module.exports = { a: 10 b: 15 }; $ node test SyntaxError: Unexpected identifier at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:404:25) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:311:12) at Module.require (module.js:366:17) at require (module.js:385:17) at Object.<anonymous> (./test.js:2:10) at Module._compile (module.js:425:26) at Object.Module._extensions..js (module.js:432:10)Ah, sorry. Misunderstanding. I meant that the legacy behavior is there if you don't catch the error. For example, if you drop the
try...catchin your last code sample. It comes down to theReportException()difference, as explained above.I would like to work on this, I'm just trying to figure out what the best approach would be. Exposing
ReportException()seems like it would require a good bit of work, since that function is pretty much hard coded to use the process stderr, while the REPL can print to arbitrary streams. I think all we really want is the hidden arrow message string, but it feels a little hackish to expose a function just for that.I'm willing to do the work once it's decided how we want to do this.
Is this possibly related to #2860?
- added a commit that references this issue
on Nov 25, 2015 - added a commit that references this issue
on Jan 7, 2016 - added a commit that references this issue
on Jan 19, 2016 Working again in master and I believe 93afc39 is responsible for that. I'll close the issue.
Issue still not fixed:
$ uname -a Linux server 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux $ node -v v5.9.0 $ cat test.js try { var a = require('./auth'); } catch (e) { console.error(e.stack); } $ cat auth.js module.exports = { a: 10 b: 15 }; $ node test SyntaxError: Unexpected identifier 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> (/some-path/test.js:2:13) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10)In REPL all ok:
$ node > require('./auth') /some-path/auth.js:3 b: 15 ^ SyntaxError: Unexpected identifier 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 repl:1:1 at REPLServer.defaultEval (repl.js:260:27) at bound (domain.js:287:14) >@amurchick It's fixed in master and will be released as v6.0.0 later this month.
- added a commit that references this issue
on Apr 2, 2016 I got the same problem with node@v4.4.6
@lichenhao please try with the v6 release line. This isn't going to be fixed in v4.
When errors in
require()'d file:I am understand - error in
auth.js, but no info where error occurred was provided - files sometimes big and no quick way to localize error.Early - some useful diagnostics was provided: