diff --git a/lib/repl.js b/lib/repl.js index 52bb1b6b53986c..7ae0f0830f06c3 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -332,7 +332,7 @@ function REPLServer(prompt, try { try { const scriptOptions = { - displayErrors: true, + displayErrors: false, breakOnSigint: self.breakEvalOnSigint }; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 741f568259a1a6..d87ae4c592fa2a 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -670,8 +670,10 @@ class ContextifyScript : public BaseObject { return; } - Local decorated_stack = String::Concat(arrow.As(), - stack.As()); + Local decorated_stack = String::Concat( + String::Concat(arrow.As(), + FIXED_ONE_BYTE_STRING(env->isolate(), "\n")), + stack.As()); err_obj->Set(env->stack_string(), decorated_stack); err_obj->SetPrivate( env->context(), @@ -867,6 +869,9 @@ class ContextifyScript : public BaseObject { env->ThrowError("Script execution timed out."); } else if (received_signal) { env->ThrowError("Script execution interrupted."); + } else if (display_errors) { + // We should decorate non-termination exceptions + DecorateErrorStack(env, *try_catch); } // If there was an exception thrown during script execution, re-throw it. @@ -879,15 +884,6 @@ class ContextifyScript : public BaseObject { return false; } - if (result.IsEmpty()) { - // Error occurred during execution of the script. - if (display_errors) { - DecorateErrorStack(env, *try_catch); - } - try_catch->ReThrow(); - return false; - } - args.GetReturnValue().Set(result); return true; } diff --git a/test/message/vm_display_runtime_error.js b/test/message/vm_display_runtime_error.js index 861e87f2f2bb93..a16afaee3d559b 100644 --- a/test/message/vm_display_runtime_error.js +++ b/test/message/vm_display_runtime_error.js @@ -4,6 +4,12 @@ const vm = require('vm'); console.error('beginning'); -vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm' }); +try { + vm.runInThisContext('throw new Error("boo!")', { filename: 'test.vm'}); +} catch (err) { + console.error(err.stack); +} + +vm.runInThisContext('throw new Error("spooky!")', { filename: 'test.vm' }); console.error('end'); diff --git a/test/message/vm_display_runtime_error.out b/test/message/vm_display_runtime_error.out index d5cf1d3ee50dbb..789f12733c163f 100644 --- a/test/message/vm_display_runtime_error.out +++ b/test/message/vm_display_runtime_error.out @@ -14,3 +14,18 @@ Error: boo! at tryModuleLoad (module.js:*:*) at Function.Module._load (module.js:*) at Module.runMain (module.js:*) +test.vm:1 +throw new Error("spooky!") +^ + +Error: spooky! + at test.vm:1:7 + at ContextifyScript.Script.runInThisContext (vm.js:*) + at Object.runInThisContext (vm.js:*) + at Object. (*test*message*vm_display_runtime_error.js:*) + at Module._compile (module.js:*) + at Object.Module._extensions..js (module.js:*) + at Module.load (module.js:*) + at tryModuleLoad (module.js:*:*) + at Function.Module._load (module.js:*) + at Module.runMain (module.js:*)