Skip to content

Commit

Permalink
bootstrap: print stack trace during environment creation failure
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
joyeecheung committed Feb 6, 2023
1 parent d592630 commit 5910278
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/api/embed_helpers.cc
Expand Up @@ -15,6 +15,7 @@ using v8::Maybe;
using v8::Nothing;
using v8::SealHandleScope;
using v8::SnapshotCreator;
using v8::TryCatch;

namespace node {

Expand Down Expand Up @@ -129,12 +130,21 @@ CommonEnvironmentSetup::CommonEnvironmentSetup(
{
Locker locker(isolate);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

TryCatch bootstrapCatch(isolate);
auto print_Exception = OnScopeLeave([&]() {
if (bootstrapCatch.HasCaught()) {
PrintCaughtException(
isolate, isolate->GetCurrentContext(), bootstrapCatch);
}
});

impl_->isolate_data.reset(CreateIsolateData(
isolate, loop, platform, impl_->allocator.get(), snapshot_data));
impl_->isolate_data->options()->build_snapshot =
impl_->snapshot_creator.has_value();

HandleScope handle_scope(isolate);
if (snapshot_data) {
impl_->env.reset(make_env(this));
if (impl_->env) {
Expand Down

0 comments on commit 5910278

Please sign in to comment.