Skip to content

Commit a9172ba

Browse files
committed
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.
1 parent 1959510 commit a9172ba

File tree

4 files changed

+181
-168
lines changed

4 files changed

+181
-168
lines changed

src/node_snapshot_builder.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ struct SnapshotData;
1515

1616
class NODE_EXTERN_PRIVATE SnapshotBuilder {
1717
public:
18-
static std::string Generate(const std::vector<std::string> args,
19-
const std::vector<std::string> exec_args);
18+
static int Generate(std::ostream& out,
19+
const std::vector<std::string> args,
20+
const std::vector<std::string> exec_args);
2021

2122
// Generate the snapshot into out.
22-
static void Generate(SnapshotData* out,
23-
const std::vector<std::string> args,
24-
const std::vector<std::string> exec_args);
23+
static int Generate(SnapshotData* out,
24+
const std::vector<std::string> args,
25+
const std::vector<std::string> exec_args);
2526

2627
// If nullptr is returned, the binary is not built with embedded
2728
// snapshot.

0 commit comments

Comments
 (0)