Skip to content

Commit

Permalink
fix(MongoInstance::checkErrorInLine): optimize "libsomething: cannot …
Browse files Browse the repository at this point in the history
…open shared object" regex

re #560
  • Loading branch information
hasezoey committed Jun 15, 2022
1 parent 0223758 commit 2b733b4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/mongodb-memory-server-core/src/util/MongoInstance.ts
Expand Up @@ -607,17 +607,25 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
)
);
}
if (/lib[^:]+(?=: cannot open shared object)/i.test(line)) {
const lib =
line.match(/(lib[^:]+)(?=: cannot open shared object)/i)?.[1].toLocaleLowerCase() ??
'unknown';
this.emit(
MongoInstanceEvents.instanceError,
new StdoutInstanceError(
`Instance failed to start because a library is missing or cannot be opened: "${lib}"`
)
);

{
/*
The following regex matches something like "libsomething.so.1: cannot open shared object"
and is optimized to only start matching at a word boundary ("\b") and using atomic-group replacement "(?=inner)\1"
*/
const liberrormatch = line.match(/\b(?=(lib[^:]+))\1: cannot open shared object/i);

if (!isNullOrUndefined(liberrormatch)) {
const lib = liberrormatch[1].toLocaleLowerCase() ?? 'unknown';
this.emit(
MongoInstanceEvents.instanceError,
new StdoutInstanceError(
`Instance failed to start because a library is missing or cannot be opened: "${lib}"`
)
);
}
}

if (/\*\*\*aborting after/i.test(line)) {
this.emit(
MongoInstanceEvents.instanceError,
Expand Down

0 comments on commit 2b733b4

Please sign in to comment.