Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab44106

Browse filesBrowse files
joyeecheungdanielleadams
authored andcommitted
tools: use PrintCaughtException in the snapshot builder
This prints not only the error message but also the error source line and the stack trace wherever possible. PR-URL: #38745 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 1f5baaa commit ab44106
Copy full SHA for ab44106

File tree

Expand file treeCollapse file tree

1 file changed

+23
-35
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-35
lines changed
Open diff view settings
Collapse file

‎tools/snapshot/snapshot_builder.cc‎

Copy file name to clipboardExpand all lines: tools/snapshot/snapshot_builder.cc
+23-35Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sstream>
44
#include "debug_utils-inl.h"
55
#include "env-inl.h"
6+
#include "node_errors.h"
67
#include "node_external_reference.h"
78
#include "node_internals.h"
89
#include "node_main_instance.h"
@@ -15,10 +16,8 @@ using v8::Context;
1516
using v8::HandleScope;
1617
using v8::Isolate;
1718
using v8::Local;
18-
using v8::Object;
1919
using v8::SnapshotCreator;
2020
using v8::StartupData;
21-
using v8::String;
2221
using v8::TryCatch;
2322
using v8::Value;
2423

@@ -112,55 +111,44 @@ std::string SnapshotBuilder::Generate(
112111
creator.SetDefaultContext(Context::New(isolate));
113112
isolate_data_indexes = main_instance->isolate_data()->Serialize(&creator);
114113

115-
TryCatch bootstrapCatch(isolate);
116-
Local<Context> context = NewContext(isolate);
117-
if (bootstrapCatch.HasCaught()) {
118-
Local<Object> obj = bootstrapCatch.Exception()->ToObject(context)
119-
.ToLocalChecked();
120-
Local<Value> stack = obj->Get(
121-
context,
122-
FIXED_ONE_BYTE_STRING(isolate, "stack")).ToLocalChecked();
123-
if (stack->IsUndefined()) {
124-
Local<String> str = obj->Get(
125-
context,
126-
FIXED_ONE_BYTE_STRING(isolate, "name"))
127-
.ToLocalChecked()->ToString(context).ToLocalChecked();
128-
str = String::Concat(
129-
isolate,
130-
str,
131-
FIXED_ONE_BYTE_STRING(isolate, ": "));
132-
stack = String::Concat(
133-
isolate,
134-
str,
135-
obj->Get(
136-
context,
137-
FIXED_ONE_BYTE_STRING(isolate, "message"))
138-
.ToLocalChecked()->ToString(context).ToLocalChecked());
114+
// Run the per-context scripts
115+
Local<Context> context;
116+
{
117+
TryCatch bootstrapCatch(isolate);
118+
context = NewContext(isolate);
119+
if (bootstrapCatch.HasCaught()) {
120+
PrintCaughtException(isolate, context, bootstrapCatch);
121+
abort();
139122
}
140-
v8::String::Utf8Value utf8_value(isolate, stack);
141-
if (*utf8_value != nullptr) {
142-
std::string out(*utf8_value, utf8_value.length());
143-
fprintf(stderr, "Had Exception: %s\n", out.c_str());
144-
} else {
145-
fprintf(stderr, "Unknown JS Exception\n");
146-
}
147-
abort();
148123
}
149124
Context::Scope context_scope(context);
150125

126+
// Create the environment
151127
env = new Environment(main_instance->isolate_data(),
152128
context,
153129
args,
154130
exec_args,
155131
nullptr,
156132
node::EnvironmentFlags::kDefaultFlags,
157133
{});
158-
env->RunBootstrapping().ToLocalChecked();
134+
// Run scripts in lib/internal/bootstrap/
135+
{
136+
TryCatch bootstrapCatch(isolate);
137+
v8::MaybeLocal<Value> result = env->RunBootstrapping();
138+
if (bootstrapCatch.HasCaught()) {
139+
PrintCaughtException(isolate, context, bootstrapCatch);
140+
}
141+
result.ToLocalChecked();
142+
}
143+
159144
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
160145
env->PrintAllBaseObjects();
161146
printf("Environment = %p\n", env);
162147
}
148+
149+
// Serialize the native states
163150
env_info = env->Serialize(&creator);
151+
// Serialize the context
164152
size_t index = creator.AddContext(
165153
context, {SerializeNodeContextInternalFields, env});
166154
CHECK_EQ(index, NodeMainInstance::kNodeContextIndex);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.