Skip to content

Commit 0f62f2b

Browse files
joyeecheungaduh95
authored andcommitted
src: print exception thrown during primordial initialization
Otherwise there's little information for debugging if the initialization fails due to a bug in local development. This should generally only happen during the build process, when the snapshot is built. Signed-off-by: Joyee Cheung <[email protected]> PR-URL: #65991 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 253784f commit 0f62f2b

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

‎src/node_realm.cc‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using v8::MaybeLocal;
1919
using v8::Object;
2020
using v8::SnapshotCreator;
2121
using v8::String;
22+
using v8::TryCatch;
2223
using v8::Value;
2324

2425
Realm::Realm(Environment* env, v8::Local<v8::Context> context, Kind kind)
@@ -64,11 +65,22 @@ void Realm::CreateProperties() {
6465
Local<Context> ctx = context();
6566

6667
// Store primordials setup by the per-context script in the environment.
67-
Local<Object> per_context_bindings =
68-
GetPerContextExports(ctx, env_->isolate_data()).ToLocalChecked();
69-
Local<Value> primordials =
70-
per_context_bindings->Get(ctx, env_->primordials_string())
71-
.ToLocalChecked();
68+
TryCatch try_catch(isolate_);
69+
Local<Object> per_context_bindings;
70+
Local<Value> primordials;
71+
if (!GetPerContextExports(ctx, env_->isolate_data())
72+
.ToLocal(&per_context_bindings) ||
73+
!per_context_bindings->Get(ctx, env_->primordials_string())
74+
.ToLocal(&primordials)) {
75+
// In general, this should only throw exceptions during local development
76+
// when there's a temporary bug in the scripts. Print the exception here to
77+
// facilitate debugging.
78+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
79+
PrintCaughtException(isolate_, ctx, try_catch);
80+
}
81+
env_->Exit(ExitCode::kBootstrapFailure);
82+
return;
83+
}
7284
CHECK(primordials->IsObject());
7385
set_primordials(primordials.As<Object>());
7486

0 commit comments

Comments
 (0)