python / python/cpython

repr(PermissionError) lacks filename information

Đang mở
#92,921 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

interpreter-core type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ PermissionError đã được báo cáo trên một hệ thống không có đặc quyền root và kiểm tra cách PermissionError lưu trữ cũng như định dạng filename của nó. Truy vết biểu diễn của exception và các test hiện có cho các subclass của OSError, sau đó thêm coverage cho thấy thông tin filename mong muốn trong repr, đồng thời duy trì hành vi của eval(repr(error)) khi áp dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.