Skip to content

Commit aa6d438

Browse files
committed
Exit on PromiseRejectCallback
This is very coarse error handling, but it's better then the current functionality: silence.
1 parent 9d8e642 commit aa6d438

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

binding.cc

+32-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,31 @@ void v8_init() {
263263
V8::Initialize();
264264
}
265265

266+
/*
267+
bool AbortOnUncaughtExceptionCallback(Isolate* isolate) {
268+
return true;
269+
}
270+
271+
void MessageCallback2(Local<Message> message, Local<Value> data) {
272+
printf("MessageCallback2\n\n");
273+
}
274+
275+
void FatalErrorCallback2(const char* location, const char* message) {
276+
printf("FatalErrorCallback2\n");
277+
}
278+
*/
279+
280+
void ExitOnPromiseRejectCallback(PromiseRejectMessage message) {
281+
auto exception = message.GetValue();
282+
283+
auto isolate = Isolate::GetCurrent();
284+
auto m = Exception::CreateMessage(isolate, exception);
285+
286+
printf("Unhandled Promise\n");
287+
m->PrintCurrentStackTrace(isolate, stdout);
288+
exit(1);
289+
}
290+
266291
worker* worker_new(int table_index) {
267292
worker* w = new (worker);
268293

@@ -275,7 +300,13 @@ worker* worker_new(int table_index) {
275300
HandleScope handle_scope(isolate);
276301

277302
w->isolate = isolate;
278-
w->isolate->SetCaptureStackTraceForUncaughtExceptions(true);
303+
// Leaving this code here because it will probably be useful later on, but
304+
// disabling it now as I haven't got tests for the desired behavior.
305+
//w->isolate->SetCaptureStackTraceForUncaughtExceptions(true);
306+
//w->isolate->SetAbortOnUncaughtExceptionCallback(AbortOnUncaughtExceptionCallback);
307+
//w->isolate->AddMessageListener(MessageCallback2);
308+
//w->isolate->SetFatalErrorHandler(FatalErrorCallback2);
309+
w->isolate->SetPromiseRejectCallback(ExitOnPromiseRejectCallback);
279310
w->isolate->SetData(0, w);
280311
w->table_index = table_index;
281312

0 commit comments

Comments
 (0)