Browse Source

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.
v0.7.4-release
isaacs 14 years ago
committed by Ryan Dahl
parent
commit
e9b6b0b327
  1. 2
      lib/events.js
  2. 8
      src/node.cc
  3. 4
      src/node.js
  4. 2
      test/message/undefined_reference_in_new_context.out

2
lib/events.js

@ -9,7 +9,7 @@ EventEmitter.prototype.emit = function (type) {
(isArray(this._events.error) && !this._events.error.length)) (isArray(this._events.error) && !this._events.error.length))
{ {
if (arguments[1] instanceof Error) { if (arguments[1] instanceof Error) {
throw arguments[1]; throw arguments[1]; // Unhandled 'error' event
} else { } else {
throw new Error("Uncaught, unspecified 'error' event."); throw new Error("Uncaught, unspecified 'error' event.");
} }

8
src/node.cc

@ -986,7 +986,15 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
if (trace.length() > 0) { if (trace.length() > 0) {
fprintf(stderr, "%s\n", *trace); 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); fflush(stderr);
} }

4
src/node.js

@ -47,7 +47,7 @@ process._tickCallback = function () {
if (i+1 < l) { if (i+1 < l) {
process._needTickCallback(); process._needTickCallback();
} }
throw e; throw e; // process.nextTick error, or 'error' event on first tick
} }
nextTickQueue.splice(0, l); nextTickQueue.splice(0, l);
@ -99,7 +99,7 @@ var module = (function () {
var m = new Module(id); var m = new Module(id);
internalModuleCache[id] = m; internalModuleCache[id] = m;
var e = m._compile(natives[id], id); var e = m._compile(natives[id], id);
if (e) throw e; if (e) throw e; // error compiling native module
return m; return m;
} }

2
test/message/undefined_reference_in_new_context.out

@ -1,7 +1,7 @@
before before
node.js:* node.js:*
throw e; throw e; // process.nextTick error, or 'error' event on first tick
^ ^
ReferenceError: foo is not defined ReferenceError: foo is not defined
at evalmachine.<anonymous>:* at evalmachine.<anonymous>:*

Loading…
Cancel
Save