Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No sanity check to see if all the required fields exists in the filters YAML file #41

Open
love-bhardwaj opened this issue Aug 18, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@love-bhardwaj
Copy link

love-bhardwaj commented Aug 18, 2020

The filter file(.yml file) should have specific required fields for snyk-filter to work correctly. These are "customFilters", "filter", "pass" and "msg". If there is a typo in any of these snyk-filter throws a type error like below:

/Users/lovebhardwaj/Tools/snyk-filter/lib/snyk-filter.js:18
  const jqFilterString = customFilters.filter;
                                       ^

TypeError: Cannot read property 'filter' of undefined

The error is ambiguous for the user. We need to have sanity( ! == null) check to see if the required fields exist in the .yml file. If not then throw an error to let the user know.

    var ymlFileInJSON = yaml.safeLoad(fs.readFileSync(filters, 'utf8'));
    customFilters = ymlFileInJSON.customFilters; 

The YAML filter file used is attached for two different cases where same error is thrown(have changed the extension from .yml to .txt since GitHub won't let me attach a .yml file). First case the problem seems to be causes by indentation and second seems to be caused by incorrect field name.

Command used:

snyk-filter -i snyk_results.json -f snyk-filter-1.yml

snyk-filter-1.txt

snyk-filter-2.txt

@love-bhardwaj love-bhardwaj changed the title Too many indentations in a filter yaml file causes customFilters.filter variable to be null No sanity check to see if all the required fields exists in the filters YAML file Aug 19, 2020
@aarlaud aarlaud added the enhancement New feature or request label Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants