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

Commit

Permalink
Fix exception output for module load exceptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
felixge authored and isaacs committed May 9, 2012
1 parent 8140333 commit bf9d8e9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
11 changes: 8 additions & 3 deletions lib/module.js
Expand Up @@ -304,11 +304,16 @@ Module._load = function(request, parent, isMain) {
}

Module._cache[filename] = module;

var hadException = true;

try {
module.load(filename);
} catch (err) {
delete Module._cache[filename];
throw err;
hadException = false;
} finally {
if (hadException) {
delete Module._cache[filename];
}
}

return module.exports;
Expand Down
6 changes: 3 additions & 3 deletions test/message/stack_overflow.out
@@ -1,6 +1,6 @@
before

module.js:311
throw err;
^
*test*message*stack_overflow.js:31

This comment has been minimized.

Copy link
@kapouer

kapouer May 16, 2012

While i get the expected result on amd64 or i386,
on arm "hard float" the stack overflow does not happen here :

[06:31|%  98|+ 345|-   0]: release stack_overflow 
                                                 
=== release stack_overflow ===
Path: message/stack_overflow
before

/build/buildd-nodejs_0.6.18~dfsg1-1-armhf-04AtjQ/nodejs-0.6.18~dfsg1/test/message/stack_overflow.js:0
(function (exports, require, module, __filename, __dirname) { // Copyright Joy
^
RangeError: Maximum call stack size exceeded
Command: out/Release/node /build/buildd-nodejs_0.6.18~dfsg1-1-armhf-04AtjQ/nodejs-0.6.18~dfsg1/test/message/stack_overflow.js
function stackOverflow() {
^
RangeError: Maximum call stack size exceeded
6 changes: 3 additions & 3 deletions test/message/throw_custom_error.out
@@ -1,6 +1,6 @@
before

module.js:311
throw err;
^
*test*message*throw_custom_error.js:31
throw { name: 'MyCustomError', message: 'This is a custom message' };
^
MyCustomError: This is a custom message
6 changes: 3 additions & 3 deletions test/message/throw_non_error.out
@@ -1,6 +1,6 @@
before

module.js:311
throw err;
^
*/test/message/throw_non_error.js:31
throw { foo: 'bar' };
^
[object Object]
6 changes: 3 additions & 3 deletions test/message/undefined_reference_in_new_context.out
@@ -1,8 +1,8 @@
before

module.js:311
throw err;
^
*test*message*undefined_reference_in_new_context.js:34
script.runInNewContext();
^
ReferenceError: foo is not defined
at evalmachine.<anonymous>:*
at Object.<anonymous> (*test*message*undefined_reference_in_new_context.js:*)
Expand Down

0 comments on commit bf9d8e9

Please sign in to comment.