php / php/php-src

Warning messages when rename() fails are stupidly vague

Aperta
#8,597 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Category: Streams Feature
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso PHP rename() e traccia il modo in cui gli errori dei lati di origine e destinazione diventano messaggi di avviso. Confronta i due casi segnalati e definisci il completamento in modo che gli avvisi identifichino quale percorso e quale operazione hanno avuto esito negativo, inclusi i casi di percorso mancante e permesso negato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, php
Ambito
operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.