Closed candrews closed 1 year ago
Thanks in advance! I'm currently traveling but will do my best to get to this in a few days!
@candrews I'm not entirely sure I get the expected result of this PR/general capability here. Do you want to "fail gracefully" or do you want to introduce a change that empty lockfiles are valid? The test suite names are a bit confusing to me with how I read this original PR's intent :)
Do you want to "fail gracefully" or do you want to introduce a change that empty lockfiles are valid?
npm
and yarn
both consider empty lock files to be invalid, so I think that failing with an error indicating that the lockfile is invalid makes the most sense.
The test suite names are a bit confusing to me with how I read this original PR's intent :)
The names of the tests that I've added in this PR are:
should fail with an empty yarn lock file
should fail with an empty npm lock file
I think those are reasonably decent names... if you have a suggestion for improving them, I'm happy to implement it #namingthingsishard
Patch coverage: 100.00
% and project coverage change: +0.01
:tada:
Comparison is base (
969ed05
) 97.74% compared to head (d386047
) 97.75%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Are you sure you've actually tested that?
The tests pass because you're asserting on a string that is part of the error, but the error still throws with a full stack trace. Is this what you expect?
@candrews making sure you see my above comment
Are you sure you've actually tested that? ![image](https://user-images.githubusercontent.com/316371
Yes, I've run similar command as you've run, and now I've even run the same one: node packages/lockfile-lint/bin/lockfile-lint.js --type yarn --path packages/lockfile-lint/__tests__/fixtures/empty.json --allowed-hosts npm
I've also run the test suite.
The tests pass because you're asserting on a string that is part of the error, but the error still throws with a full stack trace. Is this what you expect?
It is what I expected. If you pass a lock file that is invalid (like a file containing just the {
character) you also get an error with a stack trace. Therefore, the behavior implemented by this PR is consistent with the existing similar cases.
I'm happy to implement a different approach, though - tell me what you want and I'll do my best to make it happen :)
Ok then, let's land this :-)
Thank you very much!
Thank you!
Description
fix error handling for empty yarn lock files (#158)
Currently, running any validator against an empty lock file results in a exception with a stack trace, like this:
This PR fixes that issue by adding validation to the validators.
Types of changes
Related Issue
https://github.com/lirantal/lockfile-lint/issues/158
Motivation and Context
Empty lock files are not handled appropriately - this MR fixes that issue.
How Has This Been Tested?
I've added two new unit tests (one for yarn, one for npm).
Screenshots (if appropriate):
n/a
Checklist: