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:*)