php / php/php-src

Warning messages when rename() fails are stupidly vague

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

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

Category: Streams Feature
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
103

Mô tả

Description

The following code:

<?php
// Let /path/to/this-file-exists.txt be a file that exists
// Let /path/to/this-file-does-not-exist.txt be a path that does _not_ exist.
// Let /this/directory/exists be a directory that exists
// Let /this/directory/does/not/exist be a path that does _not_ exist 

rename('/path/to/this-file-exists.txt', '/this/directory/does/not/exist/newfilename.txt');
rename('/path/to/this-file-does-not-exist.txt', '/this/directory/exists/newfilename.txt');

Resulted in this output:

Warning: rename(/path/to/this-file-exists.txt, /this/directory/does/not/exist/newfilename.txt): No such file or directory
Warning: rename(/path/to/this-file-does-not-exist.txt, /this/directory/exists/newfilename.txt): No such file or directory 

That is, the EXACT SAME ERROR MESSAGE in both cases, saying "no such file or directory", but without clarifying WHAT file or directory is missing.

But I expected this output instead:
A different error message in each case, allowing me to distinguish whether the rename failed because:

  • the source file doesn't exist, or
  • the target directory doesn't exist, preventing the creation of the target file

Correct error messages in this example could be something like:

Warning: rename(/path/to/this-file-exists.txt, /this/directory/does/not/exist/newfilename.txt): Couldn't write destination file. No such file or directory: '/this/directory/does/not/exist'.
Warning: rename(/path/to/this-file-does-not-exist.txt, /this/directory/exists/newfilename.txt): Couldn't read source file. No such file or directory: '/path/to/this-file-does-not-exist.txt'

The exact same issue happens when the error is "permission denied": it does not specify on which file the permission was denied, what permission was denied (reading or writing) or whether it was on the source or target side of the operation.

I'm not exactly sure what the best and most elegant way to phrase the message is, that covers all the possible cases with the least variations, but the important thing is that it conveys all the information, and the current message definitely doesn't.

PHP Version

PHP 8.1.6

Operating System

debian 10

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 tại điểm vào rename() của PHP và theo dõi cách các lỗi từ phía nguồn và phía đích trở thành các thông báo cảnh báo. So sánh hai trường hợp được báo cáo và xác định việc hoàn tất là khi các cảnh báo chỉ ra đường dẫn và thao tác nào đã thất bại, bao gồm các trường hợp đường dẫn không tồn tại và bị từ chối quyền.

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

Đánh giá

Công nghệ
c, php
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.