forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make open_zip print realpath when raising BadZipfile. (pantsbuild#4186)
open_zip is used to unzip jars, but is usually called on files under .pants.d, which increasingly are symlinks. In the motivating example, a jar was corrupted and could not be opened by detect_duplicates task. The Exception was: ``` Exception message: Bad Zipfile /buildroot/.pants.d/<snip>/syms/org/some/corrupted.jar: \ File is not a zip file ``` The corrupted file is really at the realpath, and neither cleaning nor deleting the symlink will help. The updated output hopefully makes that more clear. This commit also adds a None check for the passed file_path. It turns out that zipfile does not filter falsey values but instead bubbles up an AttributeError that is tough to traceback: ``` # Determine file size > fpin.seek(0, 2) E AttributeError: 'NoneType' object has no attribute 'seek' ``` a custom subclass of BadZipFile to return in that instance. None of the behavior here is new, this commit just provides improved feedback. Passing None to zipfile.Zipfile has always halted execution, as did non-zip files.
- Loading branch information
Showing
2 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters