Skip to content

Commit

Permalink
fix(core): Re-throw non-require errors when using requireSearch (#1876)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Lee <[email protected]>
  • Loading branch information
MOZGIII and malept authored Aug 3, 2020
1 parent 0be4195 commit 301d6e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/api/core/src/util/require-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function requireSearchRaw<T>(relativeTo: string, paths: string[]): T | nu
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(testPath);
} catch (err) {
// Ignore the error
// Ignore require-related errors
if (err.code !== 'MODULE_NOT_FOUND' || ![undefined, testPath].includes(err.requestPath)) {
throw err;
}
}
}
d('failed to find a module in', testPaths);
Expand Down
6 changes: 6 additions & 0 deletions packages/api/core/test/fast/require-search_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ describe('require-search', () => {
const resolved = requireSearch(__dirname, ['../../src/util/forge-config']);
expect(resolved).to.equal(findConfig);
});

it('should throw if file exists but fails to load', () => {
expect(() => {
requireSearch(__dirname, ['../fixture/require-search/throw-error']);
}).to.throw('test');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('test');

0 comments on commit 301d6e1

Please sign in to comment.