Skip to content

Commit

Permalink
bootstrap: handle snapshot errors gracefully
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joyeecheung committed Jun 22, 2022
1 parent 1959510 commit a9172ba
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 168 deletions.
11 changes: 6 additions & 5 deletions src/node_snapshot_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ struct SnapshotData;

class NODE_EXTERN_PRIVATE SnapshotBuilder {
public:
static std::string Generate(const std::vector<std::string> args,
const std::vector<std::string> exec_args);
static int Generate(std::ostream& out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);

// Generate the snapshot into out.
static void Generate(SnapshotData* out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);
static int Generate(SnapshotData* out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);

// If nullptr is returned, the binary is not built with embedded
// snapshot.
Expand Down
Loading

0 comments on commit a9172ba

Please sign in to comment.