mirror of https://gitee.com/bigwinds/arangodb
Even cleaner SyntaxError stacktraces
Don't clutter stacktraces for Node compatibility at all. Just add lineNumber/columnNumber/fileName to the object. These are non-standard but there is precedent for these names in Mozilla.
This commit is contained in:
parent
88ac5777d6
commit
c9b926916a
|
@ -83,17 +83,18 @@ exports.codeFrame = function (e, basePath, withColor = false) {
|
|||
let err = e;
|
||||
while (err) {
|
||||
try {
|
||||
if (err instanceof SyntaxError) {
|
||||
const location = err.stack.split('\n')[0];
|
||||
const [fileName, lineNo, colNo] = stackParser.extractLocation(location);
|
||||
if (lineNo && colNo && (!basePath || fileName.indexOf(basePath) === 0)) {
|
||||
ctx = {
|
||||
fileName,
|
||||
lineNumber: Number(lineNo),
|
||||
columnNumber: Number(colNo)
|
||||
};
|
||||
break;
|
||||
}
|
||||
if (
|
||||
err.fileName &&
|
||||
err.lineNumber &&
|
||||
err.columnNumber &&
|
||||
(!basePath || err.fileName.indexOf(basePath) === 0)
|
||||
) {
|
||||
ctx = {
|
||||
fileName: err.fileName,
|
||||
lineNumber: Number(err.lineNumber),
|
||||
columnNumber: Number(err.columnNumber)
|
||||
};
|
||||
break;
|
||||
} else {
|
||||
const stack = stackParser.parse(err);
|
||||
for (const step of stack) {
|
||||
|
|
|
@ -412,8 +412,10 @@ static void JS_Parse(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
|||
if (tryCatch.HasCaught()) {
|
||||
if (tryCatch.CanContinue()) {
|
||||
v8::Local<v8::Object> exceptionObj = tryCatch.Exception().As<v8::Object>();
|
||||
std::string stack = TRI_StringifyV8Exception(isolate, &tryCatch);
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("stack"), TRI_V8_STD_STRING(stack));
|
||||
v8::Handle<v8::Message> message = tryCatch.Message();
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("lineNumber"), v8::Number::New(isolate, message->GetLineNumber()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("columnNumber"), v8::Number::New(isolate, message->GetStartColumn()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("fileName"), filename->ToString());
|
||||
tryCatch.ReThrow();
|
||||
return;
|
||||
} else {
|
||||
|
@ -479,8 +481,10 @@ static void JS_ParseFile(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
|||
if (tryCatch.HasCaught()) {
|
||||
if (tryCatch.CanContinue()) {
|
||||
v8::Local<v8::Object> exceptionObj = tryCatch.Exception().As<v8::Object>();
|
||||
std::string stack = TRI_StringifyV8Exception(isolate, &tryCatch);
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("stack"), TRI_V8_STD_STRING(stack));
|
||||
v8::Handle<v8::Message> message = tryCatch.Message();
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("lineNumber"), v8::Number::New(isolate, message->GetLineNumber()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("columnNumber"), v8::Number::New(isolate, message->GetStartColumn()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("fileName"), args[0]);
|
||||
tryCatch.ReThrow();
|
||||
return;
|
||||
} else {
|
||||
|
@ -1019,8 +1023,10 @@ static void JS_Execute(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
|||
|
||||
if (tryCatch.CanContinue()) {
|
||||
v8::Local<v8::Object> exceptionObj = tryCatch.Exception().As<v8::Object>();
|
||||
std::string stack = TRI_StringifyV8Exception(isolate, &tryCatch);
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("stack"), TRI_V8_STD_STRING(stack));
|
||||
v8::Handle<v8::Message> message = tryCatch.Message();
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("lineNumber"), v8::Number::New(isolate, message->GetLineNumber()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("columnNumber"), v8::Number::New(isolate, message->GetStartColumn()));
|
||||
exceptionObj->Set(TRI_V8_ASCII_STRING("fileName"), filename->ToString());
|
||||
tryCatch.ReThrow();
|
||||
return;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue