Skip to content

Commit 2c9afee

Browse files
Copilotimnasnainaec
andcommitted
Make startDatabase.js failure modes fatal with proper exit codes
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
1 parent d0942b0 commit 2c9afee

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

scripts/startDatabase.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,31 @@ async function main() {
4848
process.exit(1);
4949
});
5050

51-
const ready = await waitForMongo();
52-
if (ready) {
53-
await initReplicaSet();
54-
} else {
55-
console.error("MongoDB did not start in time");
56-
}
57-
5851
process.on("SIGINT", () => {
5952
mongod.kill("SIGINT");
6053
});
6154
process.on("SIGTERM", () => {
6255
mongod.kill("SIGTERM");
6356
});
6457

65-
await new Promise((resolve) => mongod.on("close", (code) => resolve(code)));
58+
const ready = await waitForMongo();
59+
if (!ready) {
60+
console.error("MongoDB did not start in time");
61+
mongod.kill("SIGTERM");
62+
process.exit(1);
63+
}
64+
65+
const initialized = await initReplicaSet();
66+
if (!initialized) {
67+
console.error("Replica set initialization failed");
68+
mongod.kill("SIGTERM");
69+
process.exit(1);
70+
}
71+
72+
const exitCode = await new Promise((resolve) =>
73+
mongod.on("close", (code) => resolve(code))
74+
);
75+
process.exit(exitCode || 1);
6676
}
6777

6878
main().catch((err) => {

0 commit comments

Comments
 (0)