Skip to content

Commit 03184d4

Browse files
committed
fix(MongoInstance): stdoutHandler: dont use "else if"
- dont use "else if", because input can be multiple lines and match multiple things
1 parent c5f66a3 commit 03184d4

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packages/mongodb-memory-server-core/src/util/MongoInstance.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,42 +403,53 @@ export class MongoInstance extends EventEmitter {
403403
this.debug(`STDOUT: ""${line}""`); // denoting the STDOUT string with double quotes, because the stdout might also use quotes
404404
this.emit(MongoInstanceEvents.instanceSTDOUT, line);
405405

406+
// dont use "else if", because input can be multiple lines and match multiple things
406407
if (/waiting for connections/i.test(line)) {
407408
this.emit(MongoInstanceEvents.instanceReady);
408-
} else if (/address already in use/i.test(line)) {
409+
}
410+
if (/address already in use/i.test(line)) {
409411
this.emit(MongoInstanceEvents.instanceError, `Port ${this.instanceOpts.port} already in use`);
410-
} else if (/mongod instance already running/i.test(line)) {
412+
}
413+
if (/mongod instance already running/i.test(line)) {
411414
this.emit(MongoInstanceEvents.instanceError, 'Mongod already running');
412-
} else if (/permission denied/i.test(line)) {
415+
}
416+
if (/permission denied/i.test(line)) {
413417
this.emit(MongoInstanceEvents.instanceError, 'Mongod permission denied');
414-
} else if (/Data directory .*? not found/i.test(line)) {
418+
}
419+
if (/Data directory .*? not found/i.test(line)) {
415420
this.emit(MongoInstanceEvents.instanceError, 'Data directory not found');
416-
} else if (/CURL_OPENSSL_3.*not found/i.test(line)) {
421+
}
422+
if (/CURL_OPENSSL_3.*not found/i.test(line)) {
417423
this.emit(
418424
MongoInstanceEvents.instanceError,
419425
'libcurl3 is not available on your system. Mongod requires it and cannot be started without it.\n' +
420426
'You should manually install libcurl3 or try to use an newer version of MongoDB\n'
421427
);
422-
} else if (/CURL_OPENSSL_4.*not found/i.test(line)) {
428+
}
429+
if (/CURL_OPENSSL_4.*not found/i.test(line)) {
423430
this.emit(
424431
MongoInstanceEvents.instanceError,
425432
'libcurl4 is not available on your system. Mongod requires it and cannot be started without it.\n' +
426433
'You need to manually install libcurl4\n'
427434
);
428-
} else if (/lib.*: cannot open shared object/i.test(line)) {
435+
}
436+
if (/lib.*: cannot open shared object/i.test(line)) {
429437
const lib =
430438
line.match(/(lib.*): cannot open shared object/i)?.[1].toLocaleLowerCase() ?? 'unknown';
431439
this.emit(
432440
MongoInstanceEvents.instanceError,
433441
`Instance Failed to start because an library file is missing: "${lib}"`
434442
);
435-
} else if (/\*\*\*aborting after/i.test(line)) {
443+
}
444+
if (/\*\*\*aborting after/i.test(line)) {
436445
this.emit(MongoInstanceEvents.instanceError, 'Mongod internal error');
437-
} else if (/transition to primary complete; database writes are now permitted/i.test(line)) {
446+
}
447+
if (/transition to primary complete; database writes are now permitted/i.test(line)) {
438448
this.isInstancePrimary = true;
439449
this.debug('Calling all waitForPrimary resolve functions');
440450
this.emit(MongoInstanceEvents.instancePrimary);
441-
} else if (/member [\d\.:]+ is now in state \w+/i.test(line)) {
451+
}
452+
if (/member [\d\.:]+ is now in state \w+/i.test(line)) {
442453
// "[\d\.:]+" matches "0.0.0.0:0000" (IP:PORT)
443454
const state = /member [\d\.:]+ is now in state (\w+)/i.exec(line)?.[1] ?? 'UNKNOWN';
444455
this.emit(MongoInstanceEvents.instanceReplState, state);

0 commit comments

Comments
 (0)