From bf9d8e9214e2098bacf18416564dc3a91bcdf5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Tue, 8 May 2012 22:02:28 +0200 Subject: [PATCH] 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: https://github.com/joyent/node/issues/3235 The difference is that this patch purely adresses the exception output, but does not try to make any behavior changes / improvements. --- lib/module.js | 11 ++++++++--- test/message/stack_overflow.out | 6 +++--- test/message/throw_custom_error.out | 6 +++--- test/message/throw_non_error.out | 6 +++--- test/message/undefined_reference_in_new_context.out | 6 +++--- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/module.js b/lib/module.js index bf90c9692e..c4196ed120 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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; diff --git a/test/message/stack_overflow.out b/test/message/stack_overflow.out index 1b6971da32..72dc019ff1 100644 --- a/test/message/stack_overflow.out +++ b/test/message/stack_overflow.out @@ -1,6 +1,6 @@ before -module.js:311 - throw err; - ^ +*test*message*stack_overflow.js:31 +function stackOverflow() { + ^ RangeError: Maximum call stack size exceeded diff --git a/test/message/throw_custom_error.out b/test/message/throw_custom_error.out index b5fd92b425..1406226d7d 100644 --- a/test/message/throw_custom_error.out +++ b/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 diff --git a/test/message/throw_non_error.out b/test/message/throw_non_error.out index 255e5e4d54..f0717c63c2 100644 --- a/test/message/throw_non_error.out +++ b/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] diff --git a/test/message/undefined_reference_in_new_context.out b/test/message/undefined_reference_in_new_context.out index 1e6a2d31d1..d6e9011554 100644 --- a/test/message/undefined_reference_in_new_context.out +++ b/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.:* at Object. (*test*message*undefined_reference_in_new_context.js:*)