Report "weird" errors a little better.
There are a few kinds of errors that are very confusing. 1. Errors raised in nextTick 2. Errors emitted on the "error" event 3. RangeErrors that crash the program (or anything without a stack trace) Long traces will make make these better, of course. In the meantime, this adds a few handy signposts (in the form of better error reporting and comments on the otherwise inscrutable code printed to the terminal) that can help new users find the cause, or at least, ask for help more effectively.
This commit is contained in:
parent
d59512f6f4
commit
e9b6b0b327
@ -9,7 +9,7 @@ EventEmitter.prototype.emit = function (type) {
|
||||
(isArray(this._events.error) && !this._events.error.length))
|
||||
{
|
||||
if (arguments[1] instanceof Error) {
|
||||
throw arguments[1];
|
||||
throw arguments[1]; // Unhandled 'error' event
|
||||
} else {
|
||||
throw new Error("Uncaught, unspecified 'error' event.");
|
||||
}
|
||||
|
@ -986,7 +986,15 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
|
||||
|
||||
if (trace.length() > 0) {
|
||||
fprintf(stderr, "%s\n", *trace);
|
||||
} else {
|
||||
// this really only happens for RangeErrors, since they're the only
|
||||
// kind that won't have all this info in the trace.
|
||||
Local<Value> er = try_catch.Exception();
|
||||
String::Utf8Value msg(!er->IsObject() ? er->ToString()
|
||||
: er->ToObject()->Get(String::New("message"))->ToString());
|
||||
fprintf(stderr, "%s\n", *msg);
|
||||
}
|
||||
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ process._tickCallback = function () {
|
||||
if (i+1 < l) {
|
||||
process._needTickCallback();
|
||||
}
|
||||
throw e;
|
||||
throw e; // process.nextTick error, or 'error' event on first tick
|
||||
}
|
||||
|
||||
nextTickQueue.splice(0, l);
|
||||
@ -99,7 +99,7 @@ var module = (function () {
|
||||
var m = new Module(id);
|
||||
internalModuleCache[id] = m;
|
||||
var e = m._compile(natives[id], id);
|
||||
if (e) throw e;
|
||||
if (e) throw e; // error compiling native module
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
before
|
||||
|
||||
node.js:*
|
||||
throw e;
|
||||
throw e; // process.nextTick error, or 'error' event on first tick
|
||||
^
|
||||
ReferenceError: foo is not defined
|
||||
at evalmachine.<anonymous>:*
|
||||
|
Loading…
x
Reference in New Issue
Block a user