@@ -177,7 +177,10 @@ void SnapshotBuilder::InitializeIsolateParams(const SnapshotData* data,
177
177
const_cast <v8::StartupData*>(&(data->v8_snapshot_blob_data ));
178
178
}
179
179
180
- constexpr int INTERNAL_ERROR = 12 ;
180
+ // TODO(joyeecheung): share these exit code constants across the code base.
181
+ constexpr int UNCAUGHT_EXCEPTION_ERROR = 1 ;
182
+ constexpr int BOOTSTRAP_ERROR = 10 ;
183
+ constexpr int SNAPSHOT_ERROR = 14 ;
181
184
182
185
int SnapshotBuilder::Generate (SnapshotData* out,
183
186
const std::vector<std::string> args,
@@ -237,12 +240,12 @@ int SnapshotBuilder::Generate(SnapshotData* out,
237
240
// without breaking compatibility.
238
241
Local<Context> base_context = NewContext (isolate);
239
242
if (base_context.IsEmpty ()) {
240
- return INTERNAL_ERROR ;
243
+ return BOOTSTRAP_ERROR ;
241
244
}
242
245
243
246
Local<Context> main_context = NewContext (isolate);
244
247
if (main_context.IsEmpty ()) {
245
- return INTERNAL_ERROR ;
248
+ return BOOTSTRAP_ERROR ;
246
249
}
247
250
// Initialize the main instance context.
248
251
{
@@ -259,7 +262,7 @@ int SnapshotBuilder::Generate(SnapshotData* out,
259
262
260
263
// Run scripts in lib/internal/bootstrap/
261
264
if (env->RunBootstrapping ().IsEmpty ()) {
262
- return INTERNAL_ERROR ;
265
+ return BOOTSTRAP_ERROR ;
263
266
}
264
267
// If --build-snapshot is true, lib/internal/main/mksnapshot.js would be
265
268
// loaded via LoadEnvironment() to execute process.argv[1] as the entry
@@ -272,12 +275,12 @@ int SnapshotBuilder::Generate(SnapshotData* out,
272
275
env->InitializeInspector ({});
273
276
#endif
274
277
if (LoadEnvironment (env, StartExecutionCallback{}).IsEmpty ()) {
275
- return 1 ;
278
+ return UNCAUGHT_EXCEPTION_ERROR ;
276
279
}
277
280
// FIXME(joyeecheung): right now running the loop in the snapshot
278
281
// builder seems to introduces inconsistencies in JS land that need to
279
282
// be synchronized again after snapshot restoration.
280
- int exit_code = SpinEventLoop (env).FromMaybe (1 );
283
+ int exit_code = SpinEventLoop (env).FromMaybe (UNCAUGHT_EXCEPTION_ERROR );
281
284
if (exit_code != 0 ) {
282
285
return exit_code;
283
286
}
@@ -294,7 +297,7 @@ int SnapshotBuilder::Generate(SnapshotData* out,
294
297
#ifdef NODE_USE_NODE_CODE_CACHE
295
298
// Regenerate all the code cache.
296
299
if (!native_module::NativeModuleEnv::CompileAllModules (main_context)) {
297
- return INTERNAL_ERROR ;
300
+ return UNCAUGHT_EXCEPTION_ERROR ;
298
301
}
299
302
native_module::NativeModuleEnv::CopyCodeCache (&(out->code_cache ));
300
303
for (const auto & item : out->code_cache ) {
@@ -325,7 +328,7 @@ int SnapshotBuilder::Generate(SnapshotData* out,
325
328
// We must be able to rehash the blob when we restore it or otherwise
326
329
// the hash seed would be fixed by V8, introducing a vulnerability.
327
330
if (!out->v8_snapshot_blob_data .CanBeRehashed ()) {
328
- return INTERNAL_ERROR ;
331
+ return SNAPSHOT_ERROR ;
329
332
}
330
333
331
334
// We cannot resurrect the handles from the snapshot, so make sure that
@@ -338,7 +341,7 @@ int SnapshotBuilder::Generate(SnapshotData* out,
338
341
PrintLibuvHandleInformation (env->event_loop (), stderr);
339
342
}
340
343
if (!queues_are_empty) {
341
- return INTERNAL_ERROR ;
344
+ return SNAPSHOT_ERROR ;
342
345
}
343
346
return 0 ;
344
347
}
0 commit comments