bootstrap: handle snapshot errors gracefully · nodejs/node@0aa255a · GitHub
Skip to content

Commit 0aa255a

Browse files
joyeecheungdanielleadams
authored andcommitted
bootstrap: handle snapshot errors gracefully
This patch refactors the SnapshotBuilder::Generate() routines so that when running into errors during the snapshot building process, they can exit gracefully by printing the error and return a non-zero exit code. If the error is likely to be caused by internal scripts, the return code would be 12, if the error is caused by user scripts the return code would be 1. In addition this refactors the generation of embedded snapshots and directly writes to the output file stream instead of producing an intermediate string with string streams. PR-URL: #43531 Refs: #35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 361a643 commit 0aa255a

6 files changed

Lines changed: 205 additions & 172 deletions

File tree

doc/api/process.md

Lines changed: 3 additions & 0 deletions

src/env.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,13 +963,17 @@ struct EnvSerializeInfo {
963963
};
964964

965965
struct SnapshotData {
966-
// The result of v8::SnapshotCreator::CreateBlob() during the snapshot
967-
// building process.
968-
v8::StartupData v8_snapshot_blob_data;
966+
enum class DataOwnership { kOwned, kNotOwned };
969967

970968
static const size_t kNodeBaseContextIndex = 0;
971969
static const size_t kNodeMainContextIndex = kNodeBaseContextIndex + 1;
972970

971+
DataOwnership data_ownership = DataOwnership::kOwned;
972+
973+
// The result of v8::SnapshotCreator::CreateBlob() during the snapshot
974+
// building process.
975+
v8::StartupData v8_snapshot_blob_data{nullptr, 0};
976+
973977
std::vector<size_t> isolate_data_indices;
974978
// TODO(joyeecheung): there should be a vector of env_info once we snapshot
975979
// the worker environments.
@@ -979,6 +983,15 @@ struct SnapshotData {
979983
// read only space. We use native_module::CodeCacheInfo because
980984
// v8::ScriptCompiler::CachedData is not copyable.
981985
std::vector<native_module::CodeCacheInfo> code_cache;
986+
987+
~SnapshotData();
988+
989+
SnapshotData(const SnapshotData&) = delete;
990+
SnapshotData& operator=(const SnapshotData&) = delete;
991+
SnapshotData(SnapshotData&&) = delete;
992+
SnapshotData& operator=(SnapshotData&&) = delete;
993+
994+
SnapshotData() = default;
982995
};
983996

984997
class Environment : public MemoryRetainer {

src/node_snapshot_builder.h

Lines changed: 6 additions & 5 deletions

0 commit comments

Comments
 (0)