Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: use PrintCaughtException in the snapshot builder #38745

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions tools/snapshot/snapshot_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sstream>
#include "debug_utils-inl.h"
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_main_instance.h"
Expand Down Expand Up @@ -112,55 +113,44 @@ std::string SnapshotBuilder::Generate(
creator.SetDefaultContext(Context::New(isolate));
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);

TryCatch bootstrapCatch(isolate);
Local<Context> context = NewContext(isolate);
if (bootstrapCatch.HasCaught()) {
Local<Object> obj = bootstrapCatch.Exception()->ToObject(context)
.ToLocalChecked();
Local<Value> stack = obj->Get(
context,
FIXED_ONE_BYTE_STRING(isolate, "stack")).ToLocalChecked();
if (stack->IsUndefined()) {
Local<String> str = obj->Get(
context,
FIXED_ONE_BYTE_STRING(isolate, "name"))
.ToLocalChecked()->ToString(context).ToLocalChecked();
str = String::Concat(
isolate,
str,
FIXED_ONE_BYTE_STRING(isolate, ": "));
stack = String::Concat(
isolate,
str,
obj->Get(
context,
FIXED_ONE_BYTE_STRING(isolate, "message"))
.ToLocalChecked()->ToString(context).ToLocalChecked());
// Run the per-contenxt scripts
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
Local<Context> context;
{
TryCatch bootstrapCatch(isolate);
context = NewContext(isolate);
if (bootstrapCatch.HasCaught()) {
PrintCaughtException(isolate, context, bootstrapCatch);
abort();
}
v8::String::Utf8Value utf8_value(isolate, stack);
if (*utf8_value != nullptr) {
std::string out(*utf8_value, utf8_value.length());
fprintf(stderr, "Had Exception: %s\n", out.c_str());
} else {
fprintf(stderr, "Unknown JS Exception\n");
}
abort();
}
Context::Scope context_scope(context);

// Create the environment
env = new Environment(main_instance->isolate_data(),
context,
args,
exec_args,
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});
env->RunBootstrapping().ToLocalChecked();
// Run scripts in lib/internal/bootstrap/
{
TryCatch bootstrapCatch(isolate);
v8::MaybeLocal<Value> result = env->RunBootstrapping();
if (bootstrapCatch.HasCaught()) {
PrintCaughtException(isolate, context, bootstrapCatch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PrintCaughtException(isolate, context, bootstrapCatch);
PrintCaughtException(isolate, context, bootstrapCatch);
abort();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a result.ToLocalChecked(); below which should abort the process if there's an exception

}
result.ToLocalChecked();
}

if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
env->PrintAllBaseObjects();
printf("Environment = %p\n", env);
}

// Serialize the native states
env_info = env->Serialize(&creator);
// Serialize the context
size_t index = creator.AddContext(
context, {SerializeNodeContextInternalFields, env});
CHECK_EQ(index, NodeMainInstance::kNodeContextIndex);
Expand Down