Skip Gem::Package::TarInvalidError when uploading NPM package
Context
When uploading an NPM package, we fetch its tarball archive and extract the package.json file. We then perform some validations based on the info we extract from package.json file.
However, for some packages, we can end up having an error Gem::Package::TarInvalidError (tar is corrupt, name contains null byte) while trying to find the package.json file in the tarball.
It seems that some files have invalid characters in their names, and the error is raised when calling #full_name
method on each entry in the tarball.
Solution
Rescue from Gem::Package::TarInvalidError and move to the next file. If the error was because of the package.json file, we will end up raising 'package.json not found' error. Otherwise, it was raised because of a different file that we are not interested in and it shouldn't halt the package publication.