archived-codacy / node-codacy-coverage

Code Coverage reporter for Codacy
MIT License
63 stars 45 forks source link

Shell cannot detect error #42

Closed rhuiser closed 6 years ago

rhuiser commented 7 years ago

node.js Version (7.4.0)

Operating System (Linux (Docker)

Linux e2e4d9bfe136 4.9.36-moby #1 SMP Wed Jul 12 15:29:07 UTC 2017 x86_64 GNU/Linux

Expected Behavior

When code-coverage throws an error, a non-zero value should be returned to the calling process (such as the shell under Linux) so a pipeline can fail for instance.

Actual Behavior

In case of any error, to the shell a zero "0" value is returned.

Reproducible Test Case

Some use cases below.

# Try to invoke with non-existing lcov file...
$ cat my_non_existing_lcov.info | codacy-coverage
cat: coverage/lcov.info1: No such file or directory
[error] "2017-08-15T18:12:26.068Z"  { ValidationError: "value" is not allowed to be empty
    at Object.exports.process (/usr/local/lib/node_modules/codacy-coverage/node_modules/joi/lib/errors.js:140:17)
    at internals.String.internals.Any._validateWithOptions (/usr/local/lib/node_modules/codacy-coverage/node_modules/joi/lib/any.js:654:25)
    at module.exports.internals.Any.root.validate (/usr/local/lib/node_modules/codacy-coverage/node_modules/joi/lib/index.js:100:23)
    at /usr/local/lib/node_modules/codacy-coverage/lib/impl/lcov.js:11:37
...
$ echo $?
0

# Token incorrect
cat coverage/lcov.info | codacy-coverage
[error] "2017-08-15T18:13:51.688Z"  'Status Code [404] - Error [{"error":"not found"}]'
[error] "2017-08-15T18:13:51.691Z"  'Error sending coverage'
[error] "2017-08-15T18:13:51.691Z"  Error: Expected Successful Status Code, but got [404]
    at /usr/local/lib/node_modules/codacy-coverage/lib/reporter.js:101:23

$ echo $?
0

# Token not set in ENV
cat coverage/lcov.info | codacy-coverage
[error] "2017-08-15T18:14:25.391Z"  'Error sending coverage'
[error] "2017-08-15T18:14:25.393Z"  Error: Token is required

$ echo $?
0
rhuiser commented 7 years ago

Seems very easy to fix -- if desired I can raise a pull request.

pedrorijo91 commented 7 years ago

Hey @rhuiser,

Thanks for reporting the issue. We would love to have your contribution on this one :) Let us know if you need any help!

Bgshanoams commented 6 years ago

Kool bro...