Skip to content

Commit

Permalink
Saner, yet still ugly, fix to displaying syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 24, 2010
1 parent a6f6532 commit b57c1f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -925,26 +925,24 @@ ssize_t DecodeWrite(char *buf,
return buflen;
}

// Extracts a C str from a V8 Utf8Value.
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<str conversion failed>";
}

static void ReportException(TryCatch &try_catch, bool show_line) {
void DisplayExceptionLine (TryCatch &try_catch) {
HandleScope scope;

Handle<Message> message = try_catch.Message();

node::Stdio::DisableRawMode(STDIN_FILENO);
fprintf(stderr, "\n");

if (show_line && !message.IsEmpty()) {
if (!message.IsEmpty()) {
// Print (filename):(line number): (message).
String::Utf8Value filename(message->GetScriptResourceName());
const char* filename_string = ToCString(filename);
const char* filename_string = *filename;
int linenum = message->GetLineNumber();
fprintf(stderr, "%s:%i\n", filename_string, linenum);
// Print line of source code.
String::Utf8Value sourceline(message->GetSourceLine());
const char* sourceline_string = ToCString(sourceline);
const char* sourceline_string = *sourceline;

// HACK HACK HACK
//
Expand Down Expand Up @@ -978,6 +976,14 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
}
fprintf(stderr, "\n");
}
}


static void ReportException(TryCatch &try_catch, bool show_line) {
HandleScope scope;
Handle<Message> message = try_catch.Message();

if (show_line) DisplayExceptionLine(try_catch);

String::Utf8Value trace(try_catch.StackTrace());

Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum encoding {ASCII, UTF8, BASE64, BINARY};
enum encoding ParseEncoding(v8::Handle<v8::Value> encoding_v,
enum encoding _default = BINARY);
void FatalException(v8::TryCatch &try_catch);
void DisplayExceptionLine(v8::TryCatch &try_catch); // hack

v8::Local<v8::Value> Encode(const void *buf, size_t len,
enum encoding encoding = BINARY);
Expand Down
5 changes: 3 additions & 2 deletions src/node_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ template <node::Script::EvalInputFlags iFlag,
script = oFlag == returnResult ? v8::Script::Compile(code, filename)
: v8::Script::New(code, filename);
if (script.IsEmpty()) {
// FIXME HACK TO DISPLAY SYNTAX ERRORS.
FatalException(try_catch);
// FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
DisplayExceptionLine(try_catch);

// Hack because I can't get a proper stacktrace on SyntaxError
return try_catch.ReThrow();
}
Expand Down

0 comments on commit b57c1f5

Please sign in to comment.