-
Notifications
You must be signed in to change notification settings - Fork 544
fix: fail gracefully for npm .package-lock.json files #3654
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
Conversation
* fixes intel#3559 npm has a .package-lock.json file with a similar name but slightly different format than the package-lock.json file we can parse with our javascript language parser. This changes the javascript parser so it fails more gracefully if the format of a package-lock.json file does not appear to be what we can parse. As in, it prints a warning that it was unable to parse the file and does not halt the scan. We should probably build a parser to handle these files correctly in the future, but for now this will skip them. Also, I added some docstrings to the files I changed so interrogate would be happy. Signed-off-by: Terri Oda <[email protected]>
Updating branch for tests. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3654 +/- ##
==========================================
- Coverage 79.47% 79.27% -0.21%
==========================================
Files 797 797
Lines 11944 11952 +8
Branches 1603 1605 +2
==========================================
- Hits 9493 9475 -18
- Misses 1991 2040 +49
+ Partials 460 437 -23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if "dependencies" not in data.keys(): | ||
self.logger.warning( | ||
f"Cannot parse {self.filename}: no dependencies array found." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good. The only thing I can think of is: is there a case where you can have more than 1 "dependencies" keys? If so, would it be better to also add the product and version to the warning message? (Feel free to ignore if too dumb of a comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, in theory people could give us just about anything so it would be possible, but I haven't seen any tool generate this yet or anyone complain about us not parsing it. I'll put a note about it when I file an issue about handling the npm package locks, though, since it might be relevant then.
* fixes intel#3559 npm has a .package-lock.json file with a similar name but slightly different format than the package-lock.json file we can parse with our javascript language parser. This changes the javascript parser so it fails more gracefully if the format of a package-lock.json file does not appear to be what we can parse. As in, it prints a warning that it was unable to parse the file and does not halt the scan. We should probably build a parser to handle these files correctly in the future, but for now this will skip them. Also, I added some docstrings to the files I changed so interrogate would be happy. Signed-off-by: Terri Oda <[email protected]>
* fixes intel#3559 npm has a .package-lock.json file with a similar name but slightly different format than the package-lock.json file we can parse with our javascript language parser. This changes the javascript parser so it fails more gracefully if the format of a package-lock.json file does not appear to be what we can parse. As in, it prints a warning that it was unable to parse the file and does not halt the scan. We should probably build a parser to handle these files correctly in the future, but for now this will skip them. Also, I added some docstrings to the files I changed so interrogate would be happy. Signed-off-by: Terri Oda <[email protected]>
KeyError: 'dependencies'
with npm projects #3559npm has a .package-lock.json file with a similar name but slightly different format than the package-lock.json file we can parse with our javascript language parser. This changes the javascript parser so it fails more gracefully if the format of a package-lock.json file does not appear to be what we can parse. As in, it prints a warning that it was unable to parse the file and does not halt the scan.
We should probably build a parser to handle these files correctly in the future, but for now this will skip them.
Also, I added some docstrings to the files I changed so interrogate would be happy.