Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Errors thrown in module load are not reported nicely #3235

Closed
isaacs opened this Issue · 2 comments

1 participant

@isaacs
Owner

A module like this:

// mod.js
throw new Error('yo')

reports its error like this:

$ node mod.js 

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: yo
    at Object.<anonymous> (/Users/isaacs/dev/js/node-master/mod.js:2:7)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

That "nextTick error or error event on first tick" business is very confusing and weird.

Unfortunately, fixing this will require a bit of a refactor in two places. First, the nextTick logic needs to be somewhat simplified to remove the try/catch. @felixge is working on this part of it. Second, the module load cache needs to be refactored slightly so that it does not need to use a try/catch.

@isaacs isaacs referenced this issue from a commit in isaacs/node
@isaacs isaacs Re #3235 Module cache refactor to remove try/catch 790fe62
@isaacs
Owner

With 790fe62 and 7ccc886, it prints this instead:

$ node mod.js 

Error: yo
    at Object.<anonymous> (/Users/isaacs/dev/js/node-master/mod.js:2:7)
    at Module._compile (module.js:478:26)
    at Object..js (module.js:496:10)
    at Module.load (module.js:385:32)
    at Function._load (module.js:321:12)
    at module.js:516:10
    at EventEmitter._tickCallback (node.js:235:9)
@isaacs
Owner

Actually, this is a little bit problematic. Going to focus on @felixge's v0.6 patch, and merge it in once its working properly there.

@isaacs isaacs closed this
@lizhanhui lizhanhui referenced this issue from a commit
@felixge felixge Fix exception output for module load exceptions
So instead of:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^

You will now see:

path/to/foo.js:1
throw new Error('bar');
      ^

This is a sub-set of isaacs patch here:

#3235

The difference is that this patch purely adresses the exception output,
but does not try to make any behavior changes / improvements.
bf9d8e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.