shutil.unpack_archive returns bogus ReadError exceptions when input is not found or inaccessible
Open
Nobody has claimed this yet.
stdlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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
- gh-155587
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in shutil.py around line 1311 and reproduce the missing-file and inaccessible-path commands shown in the report. Check the existing unpack_archive behavior and related tests, if present; done means these inputs expose their detailed filesystem exceptions rather than a generic ReadError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100