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

Improve Exception reporting #3238

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
12 changes: 8 additions & 4 deletions src/node.cc
Expand Up @@ -255,9 +255,7 @@ static void Spin(uv_idle_t* handle, int status) {
Tick();
}


static Handle<Value> NeedTickCallback(const Arguments& args) {
HandleScope scope;
static void StartTickSpinner() {
need_tick_cb = true;
// TODO: this tick_spinner shouldn't be necessary. An ev_prepare should be
// sufficent, the problem is only in the case of the very last "tick" -
Expand All @@ -268,9 +266,12 @@ static Handle<Value> NeedTickCallback(const Arguments& args) {
uv_idle_start(&tick_spinner, Spin);
uv_ref(uv_default_loop());
}
return Undefined();
}

static Handle<Value> NeedTickCallback(const Arguments& args) {
StartTickSpinner();
return Undefined();
}

static void PrepareTick(uv_prepare_t* handle, int status) {
assert(handle == &prepare_tick_watcher);
Expand Down Expand Up @@ -1694,6 +1695,9 @@ void FatalException(TryCatch &try_catch) {
emit->Call(process, 2, event_argv);
// Decrement so we know if the next exception is a recursion or not
uncaught_exception_counter--;

// This makes sure uncaught exceptions don't interfere with process.nextTick
StartTickSpinner();
}


Expand Down
24 changes: 8 additions & 16 deletions src/node.js
Expand Up @@ -180,26 +180,18 @@

startup.processNextTick = function() {
var nextTickQueue = [];
var nextTickIndex = 0;

process._tickCallback = function() {
var l = nextTickQueue.length;
if (l === 0) return;
var nextTickLength = nextTickQueue.length;
if (nextTickLength === 0) return;

var q = nextTickQueue;
nextTickQueue = [];

try {
for (var i = 0; i < l; i++) q[i]();
}
catch (e) {
if (i + 1 < l) {
nextTickQueue = q.slice(i + 1).concat(nextTickQueue);
}
if (nextTickQueue.length) {
process._needTickCallback();
}
throw e; // process.nextTick error, or 'error' event on first tick
while (nextTickIndex < nextTickLength) {
nextTickQueue[nextTickIndex++]();
}

nextTickQueue.splice(0, nextTickIndex);
nextTickIndex = 0;
};

process.nextTick = function(callback) {
Expand Down
6 changes: 3 additions & 3 deletions test/message/stack_overflow.out
@@ -1,6 +1,6 @@
before

node.js:*
throw e; // process.nextTick error, or 'error' event on first tick
^
*test*message*stack_overflow.js:31
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

node.js:*
throw e; // process.nextTick error, or 'error' event on first tick
^
*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

node.js:*
throw e; // process.nextTick error, or 'error' event on first tick
^
*/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

node.js:*
throw e; // process.nextTick error, or 'error' event on first tick
^
*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