Skip to content

Commit

Permalink
feat: merge "NoSystemBinaryFoundError" into "BinaryNotFoundError"
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed May 8, 2023
1 parent 6962cbe commit d4e4d63
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
import { arch, homedir, platform } from 'os';
import findCacheDir from 'find-cache-dir';
import { getOS, AnyOS, isLinuxOS, OtherOS } from './getos';
import { NoRegexMatchError, NoSystemBinaryFoundError, ParseArchiveRegexError } from './errors';
import { BinaryNotFoundError, NoRegexMatchError, ParseArchiveRegexError } from './errors';
import { MongoBinaryDownloadUrl } from './MongoBinaryDownloadUrl';

const log = debug('MongoMS:DryMongoBinary');
Expand Down Expand Up @@ -78,7 +78,7 @@ export class DryMongoBinary {
const systemReturn = await this.getSystemPath(useOpts.systemBinary);

if (isNullOrUndefined(systemReturn)) {
throw new NoSystemBinaryFoundError(useOpts.systemBinary);
throw new BinaryNotFoundError(useOpts.systemBinary, ' (systemBinary)');
}

return systemReturn;
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DryBinary locateBinary should throw an error if SystemBinary was provided, but not found 1`] = `"{\\"binaryPath\\":\\"/usr/local/bin/mongod\\"}"`;
exports[`DryBinary locateBinary should throw an error if SystemBinary was provided, but not found 1`] = `"No Binary at path \\"/usr/local/bin/mongod\\" was found! (ENOENT) (systemBinary)"`;

exports[`DryBinary parseArchiveNameRegex should throw a Error when no "version" is found [ParseArchiveRegexError] 1`] = `"Expected \\"version\\" to be found in regex groups"`;

Expand Down
Expand Up @@ -6,7 +6,7 @@ import { DEFAULT_VERSION, envName, ResolveConfigVariables } from '../resolveConf
import * as utils from '../utils';
import * as getOs from '../getos';
import { LinuxOS, OtherOS } from '../getos';
import { NoRegexMatchError, NoSystemBinaryFoundError, ParseArchiveRegexError } from '../errors';
import { BinaryNotFoundError, NoRegexMatchError, ParseArchiveRegexError } from '../errors';
import { assertIsError } from '../../__tests__/testUtils/test_utils';

describe('DryBinary', () => {
Expand Down Expand Up @@ -411,8 +411,9 @@ describe('DryBinary', () => {
await binary.DryMongoBinary.locateBinary({ version: '1.1.1' });
fail('Expected "locateBinary" to throw');
} catch (err) {
expect(err).toBeInstanceOf(NoSystemBinaryFoundError);
expect(JSON.stringify(err)).toMatchSnapshot(); // this is to test all the custom values on the error
expect(err).toBeInstanceOf(BinaryNotFoundError);
assertIsError(err);
expect(err.message).toMatchSnapshot();
expect(binary.DryMongoBinary.binaryCache.size).toBe(0);
expect(fspromises.access).toHaveBeenCalled();
}
Expand Down
13 changes: 2 additions & 11 deletions packages/mongodb-memory-server-core/src/util/errors.ts
Expand Up @@ -52,15 +52,6 @@ export class WaitForPrimaryTimeoutError extends Error {
}
}

// REFACTOR: merge this error with BinaryNotFoundError
export class NoSystemBinaryFoundError extends Error {
constructor(public binaryPath: string) {
super(
`Config option "SYSTEM_BINARY" was provided with value "${binaryPath}", but no binary could be found!`
);
}
}

export class Md5CheckFailedError extends Error {
constructor(public binarymd5: string, public checkfilemd5: string) {
super(`MD5 check failed! Binary MD5 is "${binarymd5}", Checkfile MD5 is "${checkfilemd5}"`);
Expand Down Expand Up @@ -98,8 +89,8 @@ export class InsufficientPermissionsError extends Error {
}

export class BinaryNotFoundError extends Error {
constructor(public path: string) {
super(`No Binary at path "${path}" was found! (ENOENT)`);
constructor(public path: string, public extra: string = '') {
super(`No Binary at path "${path}" was found! (ENOENT)${extra}`);
}
}

Expand Down

0 comments on commit d4e4d63

Please sign in to comment.