Skip to content

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

@love-bhardwaj

Description

@love-bhardwaj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions