Skip to content

Commit 473c278

Browse files
committed
fix(MongoInstance::checkErrorInLine): optimize "exception in initAndListen" regex
re #560
1 parent 2b733b4 commit 473c278

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

+15-11
Original file line numberDiff line numberDiff line change
@@ -574,21 +574,25 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
574574
new StdoutInstanceError(`Port "${this.instanceOpts.port}" already in use`)
575575
);
576576
}
577-
if (/exception in initAndListen: \w+[^:]: .+[^,], terminating/i.test(line)) {
578-
// in pre-4.0 mongodb this exception may have been "permission denied" and "Data directory /path not found"
579577

580-
// this variable cannot actually be "null", because of the previous test
581-
const matches = /exception in initAndListen: (\w+[^:]): (.+[^,]), terminating/i.exec(line);
578+
{
579+
const execptionMatch = /\bexception in initAndListen: (\w+): /i.exec(line);
582580

583-
const { 1: errorName, 2: origError } = matches || [];
581+
if (!isNullOrUndefined(execptionMatch)) {
582+
// in pre-4.0 mongodb this exception may have been "permission denied" and "Data directory /path not found"
584583

585-
this.emit(
586-
MongoInstanceEvents.instanceError,
587-
new StdoutInstanceError(
588-
`Instance Failed to start with "${errorName}". Original Error:\n` + origError
589-
)
590-
);
584+
this.emit(
585+
MongoInstanceEvents.instanceError,
586+
new StdoutInstanceError(
587+
`Instance Failed to start with "${execptionMatch[1] ?? 'unknown'}". Original Error:\n` +
588+
line
589+
.substring(execptionMatch.index + execptionMatch[0].length)
590+
.replaceAll(/, terminating$/gi, '')
591+
)
592+
);
593+
}
591594
}
595+
592596
if (/CURL_OPENSSL_3['\s]+not found/i.test(line)) {
593597
this.emit(
594598
MongoInstanceEvents.instanceError,

0 commit comments

Comments
 (0)