Skip to content

Commit d066643

Browse files
committed
fix(errors): add helper message if exit code is large on windows for "UnexpectedCloseError"
re #748
1 parent 8c224d1 commit d066643

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,22 @@ describe('MongodbInstance', () => {
389389
expect(event.message).toMatchSnapshot();
390390
}
391391
});
392+
393+
it('"closeHandler" should emit "instanceError" with vc_redist helper message on windows on high exit code', () => {
394+
events.clear();
395+
Object.defineProperty(process, 'platform', {
396+
value: 'win32',
397+
});
398+
399+
mongod.closeHandler(3221225785, null);
400+
401+
expect(events.get(MongoInstanceEvents.instanceClosed)).toEqual([3221225785, null]);
402+
403+
const event = events.get(MongoInstanceEvents.instanceError)?.[0];
404+
expect(event).toBeInstanceOf(UnexpectedCloseError);
405+
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
406+
expect(event.message).toMatchSnapshot();
407+
});
392408
});
393409

394410
describe('stdoutHandler()', () => {

packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoInstance.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ exports[`MongodbInstance test events "start" should emit a "instanceError" when
1010

1111
exports[`MongodbInstance test events checkErrorInLine() should emit "instanceError" when shared libraries fail to load 1`] = `"Instance failed to start because a library is missing or cannot be opened: \\"libcrypto.so.1.1\\""`;
1212

13+
exports[`MongodbInstance test events closeHandler() "closeHandler" should emit "instanceError" with vc_redist helper message on windows on high exit code 1`] = `
14+
"Instance closed unexpectedly with code \\"3221225785\\" and signal \\"null\\"
15+
Exit Code is large, commonly meaning that vc_redist is not installed, the latest vc_redist can be found at https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170"
16+
`;
17+
1318
exports[`MongodbInstance test events closeHandler() should emit "instanceClosed" 1`] = `"Instance closed unexpectedly with code \\"null\\" and signal \\"SIG\\""`;
1419

1520
exports[`MongodbInstance test events closeHandler() should emit "instanceError" with extra information on "SIGILL" 1`] = `

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ export class UnexpectedCloseError extends Error {
183183
this.message +=
184184
'\nThe Process Exited with SIGILL, which mean illegal instruction, which is commonly thrown in mongodb 5.0+ when not having AVX available on the CPU';
185185
}
186+
187+
if (process.platform === 'win32' && (code ?? 0) > 1000000000) {
188+
this.message +=
189+
'\nExit Code is large, commonly meaning that vc_redist is not installed, the latest vc_redist can be found at https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170';
190+
}
186191
}
187192
}
188193

0 commit comments

Comments
 (0)