Skip to content

Commit

Permalink
Merge pull request #199 from snyk/fix/error-handle-invalid-dot-snyk
Browse files Browse the repository at this point in the history
fix: descriptive error when .snyk contains invalid ignores
  • Loading branch information
Serhiy Vasilkov authored Aug 4, 2023
2 parents 282ef8f + 370e654 commit b1f6dea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ export function parseFileIgnores(path: string): string[] {
);
}
}
return parseIgnoreRulesToGlobs(rules, dirname);
try {
return parseIgnoreRulesToGlobs(rules, dirname);
} catch (err) {
console.error('Could not parse ignore rules to glob', { path });
throw new Error('Please make sure ignore file follows correct syntax');
}
}

export function getGlobPatterns(supportedFiles: SupportedFiles): string[] {
Expand Down
5 changes: 5 additions & 0 deletions tests/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ describe('files', () => {
const patterns = parseFileIgnores(`${sampleProjectPath}/exclude/.snyk`);
expect(patterns).toEqual(bundleFileIgnores.slice(12));
});
it('fails to parse dot snyk file with invalid field', () => {
expect(() => parseFileIgnores(`${sampleProjectPath}/invalid-dot-snyk/.snyk.invalid`)).toThrow(
'Please make sure ignore file follows correct syntax',
);
});

it('collect ignore rules', async () => {
const ignoreRules = await collectIgnoreRules([sampleProjectPath]);
Expand Down
6 changes: 6 additions & 0 deletions tests/sample-repo/invalid-dot-snyk/.snyk.invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exclude:
global:
- some/excluded/folder:
reason: None Given
expires: 2022-04-17T12:57:47.569Z
created: 2022-03-18T12:57:47.576Z

0 comments on commit b1f6dea

Please sign in to comment.