Skip to content

Commit

Permalink
fix(MongoInstance::checkErrorInLine): optimize "exception in initAndL…
Browse files Browse the repository at this point in the history
…isten" regex

re #560
  • Loading branch information
hasezoey committed Jun 15, 2022
1 parent 2b733b4 commit 473c278
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/mongodb-memory-server-core/src/util/MongoInstance.ts
Expand Up @@ -574,21 +574,25 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
new StdoutInstanceError(`Port "${this.instanceOpts.port}" already in use`)
);
}
if (/exception in initAndListen: \w+[^:]: .+[^,], terminating/i.test(line)) {
// in pre-4.0 mongodb this exception may have been "permission denied" and "Data directory /path not found"

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

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

this.emit(
MongoInstanceEvents.instanceError,
new StdoutInstanceError(
`Instance Failed to start with "${errorName}". Original Error:\n` + origError
)
);
this.emit(
MongoInstanceEvents.instanceError,
new StdoutInstanceError(
`Instance Failed to start with "${execptionMatch[1] ?? 'unknown'}". Original Error:\n` +
line
.substring(execptionMatch.index + execptionMatch[0].length)
.replaceAll(/, terminating$/gi, '')
)
);
}
}

if (/CURL_OPENSSL_3['\s]+not found/i.test(line)) {
this.emit(
MongoInstanceEvents.instanceError,
Expand Down

0 comments on commit 473c278

Please sign in to comment.