Skip to content

Commit 5910278

Browse files
committed
bootstrap: print stack trace during environment creation failure
nodejs#45888 took the environment creation code out of the scope covered by the v8::TryCatch that we use to print early failures during environment creation. So e.g. when adding something that would fail in node.js, we get ``` node:internal/options:554: Uncaught Error: Should not query options before bootstrapping is done ``` This patch restores that by adding another v8::TryCatch for it: ``` node:internal/options:20 ({ options: optionsMap } = getCLIOptions()); ^ Error: Should not query options before bootstrapping is done at getCLIOptionsFromBinding (node:internal/options:20:32) at getOptionValue (node:internal/options:45:19) at node:internal/bootstrap/node:433:29 ```
1 parent d592630 commit 5910278

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/api/embed_helpers.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using v8::Maybe;
1515
using v8::Nothing;
1616
using v8::SealHandleScope;
1717
using v8::SnapshotCreator;
18+
using v8::TryCatch;
1819

1920
namespace node {
2021

@@ -129,12 +130,21 @@ CommonEnvironmentSetup::CommonEnvironmentSetup(
129130
{
130131
Locker locker(isolate);
131132
Isolate::Scope isolate_scope(isolate);
133+
HandleScope handle_scope(isolate);
134+
135+
TryCatch bootstrapCatch(isolate);
136+
auto print_Exception = OnScopeLeave([&]() {
137+
if (bootstrapCatch.HasCaught()) {
138+
PrintCaughtException(
139+
isolate, isolate->GetCurrentContext(), bootstrapCatch);
140+
}
141+
});
142+
132143
impl_->isolate_data.reset(CreateIsolateData(
133144
isolate, loop, platform, impl_->allocator.get(), snapshot_data));
134145
impl_->isolate_data->options()->build_snapshot =
135146
impl_->snapshot_creator.has_value();
136147

137-
HandleScope handle_scope(isolate);
138148
if (snapshot_data) {
139149
impl_->env.reset(make_env(this));
140150
if (impl_->env) {

0 commit comments

Comments
 (0)