Skip to content

Commit

Permalink
fix(errors): add helper message if exit code is large on windows for …
Browse files Browse the repository at this point in the history
…"UnexpectedCloseError"

re #748
  • Loading branch information
hasezoey committed Mar 17, 2023
1 parent 8c224d1 commit d066643
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ describe('MongodbInstance', () => {
expect(event.message).toMatchSnapshot();
}
});

it('"closeHandler" should emit "instanceError" with vc_redist helper message on windows on high exit code', () => {
events.clear();
Object.defineProperty(process, 'platform', {
value: 'win32',
});

mongod.closeHandler(3221225785, null);

expect(events.get(MongoInstanceEvents.instanceClosed)).toEqual([3221225785, null]);

const event = events.get(MongoInstanceEvents.instanceError)?.[0];
expect(event).toBeInstanceOf(UnexpectedCloseError);
assertIsError(event); // has to be used, because there is not typeguard from "expect(variable).toBeInstanceOf"
expect(event.message).toMatchSnapshot();
});
});

describe('stdoutHandler()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ exports[`MongodbInstance test events "start" should emit a "instanceError" when

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\\""`;

exports[`MongodbInstance test events closeHandler() "closeHandler" should emit "instanceError" with vc_redist helper message on windows on high exit code 1`] = `
"Instance closed unexpectedly with code \\"3221225785\\" and signal \\"null\\"
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"
`;

exports[`MongodbInstance test events closeHandler() should emit "instanceClosed" 1`] = `"Instance closed unexpectedly with code \\"null\\" and signal \\"SIG\\""`;

exports[`MongodbInstance test events closeHandler() should emit "instanceError" with extra information on "SIGILL" 1`] = `
Expand Down
5 changes: 5 additions & 0 deletions packages/mongodb-memory-server-core/src/util/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export class UnexpectedCloseError extends Error {
this.message +=
'\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';
}

if (process.platform === 'win32' && (code ?? 0) > 1000000000) {
this.message +=
'\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';
}
}
}

Expand Down

0 comments on commit d066643

Please sign in to comment.