Skip to content

shutil.unpack_archive returns bogus ReadError exceptions when input is not found or inaccessible #98758

Description

@keszybz

Bug report

$ python -c 'import shutil; shutil.unpack_archive("./enoent")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.11/shutil.py", line 1311, in unpack_archive
    raise ReadError("Unknown archive format '{0}'".format(filename))
shutil.ReadError: Unknown archive format './enoent'

$ python -c 'import shutil; shutil.unpack_archive("/root/inaccessible")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.11/shutil.py", line 1311, in unpack_archive
    raise ReadError("Unknown archive format '{0}'".format(filename))
shutil.ReadError: Unknown archive format '/root/inaccessible'

The generic exception makes it handle to handle the error programatically, and the message is also very confusing to the user. Instead, the function should just propagate the detailed exception it got internally. Compare with open:

$ python -c 'open("./enoent")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: './enoent'

$ python -c 'open("/root/inaccessible")' 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/root/inaccessible'

Your environment

python3-3.11.0-1.fc37.x86_64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions