php / php/php-src

Warning messages when rename() fails are stupidly vague

Offen
#8,597 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Category: Streams Feature
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne am PHP-Einstiegspunkt rename() und verfolge, wie Fehler von der Quell- und Zielseite zu Warnmeldungen werden. Vergleiche die beiden gemeldeten Fälle und definiere den Abschluss so, dass Warnungen den Pfad und die fehlgeschlagene Operation angeben, einschließlich der Fälle mit fehlendem Pfad und verweigerter Berechtigung.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.