File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -75,3 +75,10 @@ This Error gets thrown when this package runs on an unsupported architecture by
7575## BinaryNotFoundError
7676
7777* extend documentation*
78+
79+ ## AssertionFallbackError
80+
81+ Example: ` Assert failed - no custom error `
82+
83+ Details:
84+ This Error gets thrown when no custom error to ` assertion ` is given, this should never happen
Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ import { ChildProcess } from 'child_process';
33import * as utils from '../utils' ;
44import * as tmp from 'tmp' ;
55import { resolve } from 'path' ;
6- import { BinaryNotFoundError , InsufficientPermissionsError } from '../errors' ;
6+ import {
7+ AssertionFallbackError ,
8+ BinaryNotFoundError ,
9+ InsufficientPermissionsError ,
10+ } from '../errors' ;
711import { assertIsError } from '../../__tests__/testUtils/test_utils' ;
812
913tmp . setGracefulCleanup ( ) ;
@@ -47,13 +51,18 @@ describe('utils', () => {
4751 } ) ;
4852
4953 describe ( 'assertion' , ( ) => {
54+ it ( 'should run without error' , ( ) => {
55+ expect ( utils . assertion ( true ) ) . toStrictEqual ( void 0 ) ;
56+ } ) ;
57+
5058 it ( 'should throw default error if none provided' , ( ) => {
51- expect . assertions ( 1 ) ;
59+ expect . assertions ( 2 ) ;
5260 try {
5361 utils . assertion ( false ) ;
5462 fail ( 'Expected Assertion to Throw' ) ;
5563 } catch ( err ) {
5664 assertIsError ( err ) ;
65+ expect ( err ) . toBeInstanceOf ( AssertionFallbackError ) ;
5766 expect ( err . message ) . toMatchSnapshot ( ) ;
5867 }
5968 } ) ;
Original file line number Diff line number Diff line change @@ -115,3 +115,12 @@ export class BinaryNotFoundError extends Error {
115115 super ( `No Binary at path "${ path } " was found! (ENOENT)` ) ;
116116 }
117117}
118+
119+ /**
120+ * Custom Fallback Error for "utils.assertion", it is a named/custom Error to confuse less in the stacktrace
121+ */
122+ export class AssertionFallbackError extends Error {
123+ constructor ( ) {
124+ super ( 'Assert failed - no custom error' ) ;
125+ }
126+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ import { ChildProcess } from 'child_process';
33import { AutomaticAuth } from '../MongoMemoryServer' ;
44import { promises as fspromises , Stats , constants } from 'fs' ;
55import { LinuxOS } from './getos' ;
6- import { BinaryNotFoundError , InsufficientPermissionsError } from './errors' ;
6+ import {
7+ AssertionFallbackError ,
8+ BinaryNotFoundError ,
9+ InsufficientPermissionsError ,
10+ } from './errors' ;
711
812const log = debug ( 'MongoMS:utils' ) ;
913
@@ -76,7 +80,7 @@ export function isNullOrUndefined(val: unknown): val is null | undefined {
7680 */
7781export function assertion ( cond : unknown , error ?: Error ) : asserts cond {
7882 if ( ! cond ) {
79- throw error ?? new Error ( 'Assert failed - no custom error' ) ;
83+ throw error ?? new AssertionFallbackError ( ) ;
8084 }
8185}
8286
You can’t perform that action at this time.
0 commit comments