repr(PermissionError) lacks filename information
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
repr(PermissionError) looses the information about the affected filename, because it only returns PermissionError(13, 'Permission denied'). Example code to demonstrate that (run as non-root):
#!/usr/bin/python3
try:
open("/path-with-no-write-access", "w")
except PermissionError as error:
print(f"error = {error}")
print(f"eval(repr(error)) = {eval(repr(error))}")
Output of this code:
error = [Errno 13] Permission denied: '/path-with-no-write-access'
eval(repr(error)) = [Errno 13] Permission denied
I also failed to figure out how to raise a PermissionError with a filename specified. PermissionError takes no keyword arguments.
Rational
apport uses repr(error) in UserInterface.collect_info() in case the thread_collect_info thread crashes to present this information to the user. One test case failed with PermissionError(13, 'Permission denied') which did not help at all to trouble shoot the failure. If the representation of the exception had included the filename, it would have saved me time.
Your environment
- CPython versions tested on: 3.10.4
- Operating system and architecture: Ubuntu 22.04 LTS (jammy)
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 by reproducing the reported PermissionError example on a non-root system and inspect how PermissionError stores and formats its filename. Trace the exception representation and existing tests for OSError subclasses, then add coverage showing the desired filename information in repr while preserving eval(repr(error)) behavior where applicable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100