InfoSec812 / npm-audit-ci-wrapper

A wrapper for 'npm audit' which can be configurable for use in a CI/CD tool like Jenkins
Apache License 2.0
13 stars 11 forks source link

Execution fails with 'An unexpected error has occurred' #6

Closed d0tkom closed 5 years ago

d0tkom commented 5 years ago

For some of my projects running npm-audit-ci-wrapper fails with 'An unexpected error has occurred'. I looked into the code, and was wondering what's the reason for throwing this error here if err is null?

  let exitCode = 0;
  if (err === null) {
    console.log('An unexpected error has occurred')
    console.log(stderr);
    exitCode = 255;
  } else {

as far as I know if everything goes correctly, err should be null no?

InfoSec812 commented 5 years ago

Interesting... I checked the docs on the exec method and your reasoning makes sense, but for some reason it has been working for me all of this time. Could you propose a PR and we can have a look?

TazSp commented 5 years ago

npm audit returns success when there are no vulnerabilities as an exit code 0 which would make err be null. So (at least for me) npm-audit-ci-wrapper throws "An unexpected error has occurred" when there are no vulnerabilities. It seems logical npm-audit-ci-wrapper should exit with 0 in this case (which makes it useful in a CI pipeline).

InfoSec812 commented 5 years ago

@TazSp Makes sense. I'd be happy to review a PR.

InfoSec812 commented 5 years ago

This was resolved by #11