diff options
| author | Anthony Sottile <asottile@umich.edu> | 2021-04-27 10:39:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-27 10:39:01 -0700 |
| commit | 9aea31deddf7458be3546f72185740f3cd06687f (patch) | |
| tree | af1d9b0bd0091d8b50098ec3896151564e31818f /Lib/tarfile.py | |
| parent | 8a37463989410a79f6d1131d08dc0165bcaa0f9d (diff) | |
| download | cpython-git-9aea31deddf7458be3546f72185740f3cd06687f.tar.gz | |
bpo-8978: improve tarfile.open error message when lzma / bz2 are missing (GH-24850)
Automerge-Triggered-By: GH:pablogsal
Diffstat (limited to 'Lib/tarfile.py')
| -rwxr-xr-x | Lib/tarfile.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 395c0f1d30..18d415adf5 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1604,17 +1604,20 @@ class TarFile(object): # Find out which *open() is appropriate for opening the file. def not_compressed(comptype): return cls.OPEN_METH[comptype] == 'taropen' + error_msgs = [] for comptype in sorted(cls.OPEN_METH, key=not_compressed): func = getattr(cls, cls.OPEN_METH[comptype]) if fileobj is not None: saved_pos = fileobj.tell() try: return func(name, "r", fileobj, **kwargs) - except (ReadError, CompressionError): + except (ReadError, CompressionError) as e: + error_msgs.append(f'- method {comptype}: {e!r}') if fileobj is not None: fileobj.seek(saved_pos) continue - raise ReadError("file could not be opened successfully") + error_msgs_summary = '\n'.join(error_msgs) + raise ReadError(f"file could not be opened successfully:\n{error_msgs_summary}") elif ":" in mode: filemode, comptype = mode.split(":", 1) |
