Hack to display more useful SyntaxError exceptions.
For some reason v8 doesn't include the frame with the syntax error in the stack trace - so have to special case it.
This commit is contained in:
parent
6c5c808569
commit
8e6dd52683
22
src/node.cc
22
src/node.cc
@ -316,7 +316,7 @@ const char* ToCString(const v8::String::Utf8Value& value) {
|
|||||||
return *value ? *value : "<str conversion failed>";
|
return *value ? *value : "<str conversion failed>";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ReportException(TryCatch *try_catch) {
|
static void ReportException(TryCatch *try_catch, bool show_line = false) {
|
||||||
Handle<Message> message = try_catch->Message();
|
Handle<Message> message = try_catch->Message();
|
||||||
if (message.IsEmpty()) {
|
if (message.IsEmpty()) {
|
||||||
fprintf(stderr, "Error: (no message)\n");
|
fprintf(stderr, "Error: (no message)\n");
|
||||||
@ -333,7 +333,7 @@ static void ReportException(TryCatch *try_catch) {
|
|||||||
if (raw_stack->IsString()) stack = Handle<String>::Cast(raw_stack);
|
if (raw_stack->IsString()) stack = Handle<String>::Cast(raw_stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.IsEmpty()) {
|
if (show_line) {
|
||||||
// Print (filename):(line number): (message).
|
// Print (filename):(line number): (message).
|
||||||
String::Utf8Value filename(message->GetScriptResourceName());
|
String::Utf8Value filename(message->GetScriptResourceName());
|
||||||
const char* filename_string = ToCString(filename);
|
const char* filename_string = ToCString(filename);
|
||||||
@ -353,7 +353,9 @@ static void ReportException(TryCatch *try_catch) {
|
|||||||
fprintf(stderr, "^");
|
fprintf(stderr, "^");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.IsEmpty()) {
|
||||||
message->PrintCurrentStackTrace(stderr);
|
message->PrintCurrentStackTrace(stderr);
|
||||||
} else {
|
} else {
|
||||||
String::Utf8Value trace(stack);
|
String::Utf8Value trace(stack);
|
||||||
@ -736,7 +738,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
|||||||
return Undefined();
|
return Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Handle<v8::Value> Compile(const v8::Arguments& args) {
|
Handle<Value> Compile(const Arguments& args) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
if (args.Length() < 2) {
|
if (args.Length() < 2) {
|
||||||
@ -747,11 +749,17 @@ v8::Handle<v8::Value> Compile(const v8::Arguments& args) {
|
|||||||
Local<String> source = args[0]->ToString();
|
Local<String> source = args[0]->ToString();
|
||||||
Local<String> filename = args[1]->ToString();
|
Local<String> filename = args[1]->ToString();
|
||||||
|
|
||||||
Handle<Script> script = Script::Compile(source, filename);
|
TryCatch try_catch;
|
||||||
if (script.IsEmpty()) return Undefined();
|
|
||||||
|
|
||||||
Handle<Value> result = script->Run();
|
Local<Script> script = Script::Compile(source, filename);
|
||||||
if (result.IsEmpty()) return Undefined();
|
if (try_catch.HasCaught()) {
|
||||||
|
// Hack because I can't get a proper stacktrace on SyntaxError
|
||||||
|
ReportException(&try_catch, true);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Local<Value> result = script->Run();
|
||||||
|
if (try_catch.HasCaught()) return try_catch.ReThrow();
|
||||||
|
|
||||||
return scope.Close(result);
|
return scope.Close(result);
|
||||||
}
|
}
|
||||||
|
@ -921,9 +921,9 @@ Module.prototype.loadScript = function (filename, loadPromise) {
|
|||||||
var wrapper = "var __wrap__ = function (exports, require, module, __filename) { "
|
var wrapper = "var __wrap__ = function (exports, require, module, __filename) { "
|
||||||
+ content
|
+ content
|
||||||
+ "\n}; __wrap__;";
|
+ "\n}; __wrap__;";
|
||||||
var compiledWrapper = process.compile(wrapper, filename);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
var compiledWrapper = process.compile(wrapper, filename);
|
||||||
compiledWrapper.apply(self.exports, [self.exports, require, self, filename]);
|
compiledWrapper.apply(self.exports, [self.exports, require, self, filename]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadPromise.emitError(e);
|
loadPromise.emitError(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user