php / php/php-src

Warning messages when rename() fails are stupidly vague

オープン
#8,597 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Streams Feature
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

PHP の rename() エントリポイントから開始し、ソース側とデスティネーション側の失敗がどのように警告メッセージになるかを追跡します。報告された 2 つのケースを比較し、警告が失敗したパスと操作を特定することを完了条件として定義します。これには、パスが存在しない場合と権限が拒否された場合を含めます。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。