vm: don't print out arrow message for custom error · nodejs/node@6151544 · GitHub
Skip to content

Commit 6151544

Browse files
addaleaxFishrock123
authored andcommitted
vm: don't print out arrow message for custom error
In `AppendExceptionLine()`, which is used both by the `vm` module and the uncaught exception handler, don’t print anything to stderr when called from the `vm` module, even if the thrown object is not a native error instance. Fixes: #7397 PR-URL: #7398 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8d18aed commit 6151544

5 files changed

Lines changed: 45 additions & 15 deletions

File tree

src/node.cc

Lines changed: 20 additions & 13 deletions

src/node_contextify.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ class ContextifyScript : public BaseObject {
633633
if (IsExceptionDecorated(env, err_obj))
634634
return;
635635

636-
AppendExceptionLine(env, exception, try_catch.Message());
636+
AppendExceptionLine(env, exception, try_catch.Message(), CONTEXTIFY_ERROR);
637637
Local<Value> stack = err_obj->Get(env->stack_string());
638638
auto maybe_value =
639639
err_obj->GetPrivate(

src/node_internals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ constexpr size_t arraysize(const T(&)[N]) { return N; }
142142

143143
bool IsExceptionDecorated(Environment* env, v8::Local<v8::Value> er);
144144

145+
enum ErrorHandlingMode { FATAL_ERROR, CONTEXTIFY_ERROR };
145146
void AppendExceptionLine(Environment* env,
146147
v8::Local<v8::Value> er,
147-
v8::Local<v8::Message> message);
148+
v8::Local<v8::Message> message,
149+
enum ErrorHandlingMode mode);
148150

149151
NO_RETURN void FatalError(const char* location, const char* message);
150152

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
require('../common');
3+
const vm = require('vm');
4+
5+
console.error('beginning');
6+
7+
// Regression test for https://github.com/nodejs/node/issues/7397:
8+
// vm.runInThisContext() should not print out anything to stderr by itself.
9+
try {
10+
vm.runInThisContext(`throw ({
11+
name: 'MyCustomError',
12+
message: 'This is a custom message'
13+
})`, { filename: 'test.vm' });
14+
} catch (e) {
15+
console.error('received error', e.name);
16+
}
17+
18+
console.error('end');
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)