diff --git a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts index b335eb176..432f4d3c1 100644 --- a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts +++ b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts @@ -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'); @@ -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; diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/dryBinary.test.ts.snap b/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/dryBinary.test.ts.snap index dc3a34c4c..886b67781 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/dryBinary.test.ts.snap +++ b/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/dryBinary.test.ts.snap @@ -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"`; diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts index 6e089fb83..eb733ef97 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts +++ b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts @@ -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', () => { @@ -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(); } diff --git a/packages/mongodb-memory-server-core/src/util/errors.ts b/packages/mongodb-memory-server-core/src/util/errors.ts index 08c8b91f8..bfe5608be 100644 --- a/packages/mongodb-memory-server-core/src/util/errors.ts +++ b/packages/mongodb-memory-server-core/src/util/errors.ts @@ -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}"`); @@ -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}`); } }