Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.1

Request #14076 Gracefully handle permission denied errors (filesystem)
Submitted: 2008-06-05 03:20 UTC
From: doconnor Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.0.1)
PHP Version: 5.2.6 OS:
Roadmaps: 1.1.0    

 [2008-06-05 03:20 UTC] doconnor (Daniel O'Connor)
Description: ------------ If I run phpcs over my codebase, and it hits a directory it cannot handle, it raises an exception I would have expected the phpcs command line tool to gracefully handle this and print a meaningful error to the end user Test script: --------------- su mkdir /foo/bar/dir_without_read_permissions mkdir /foo/bar/dir_with_read_permissions chmod 777 /foo/bar/dir_with_read_permissions su some_other_user cd /foo/bar/ phpcs * Expected result: ---------------- /foo/bar/dir_without_read_permissions/): failed to open dir: Permission denied ... continues processing dir_with_read_permissions Actual result: -------------- Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/usr/files/trunk/cache/cache_7): failed to open dir: Permission denied' in /usr/share/php/PHP/CodeSniffer.php:493


 [2008-06-12 05:19 UTC] squiz (Greg Sherwood)
I don't know how to continue after the exception is caught. The directory iterator is the bit actually throwing the exception and the process of trying to move to the next element is the cause. I can't put a try/catch block that will allow me to continue to the next element. All I can do is print a different error message and stop processing.
 [2008-06-12 07:19 UTC] doconnor (Daniel O'Connor)
:( Is there any way to just: - Process files and discover all available paths just using RecursiveDirectoryIterator (no RecursiveIteratorIterator) and checking foreach ($dir as $file) { if (!is_readable($file)) { continue; } } ? - Push all of the accessable paths onto an array - Do a second pass: actually sniffing those files
 [2008-06-12 08:48 UTC] squiz (Greg Sherwood)
That may be possible, but that is a lot of additional processing for the rare case you don't have permission to a file. I'm planning on just throwing an error to let you know and then showing you the errors generated up to that point. You can then fix those errors and the permissions before trying again.
 [2008-06-13 02:32 UTC] squiz (Greg Sherwood)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. PHPCS now throws a phpcs error for a file that it does not have permission to read. This allows it to still be shown when using all output formats instead of producing an exception. Some sample output showing a file with errors and the final file execution died on: [gsherwood@fedora scripts]$ php phpcs ~/PHP_CodeSniffer/CodeSniffer/Standards/Zend FILE: ...rwood/PHP_CodeSniffer/CodeSniffer/Standards/Zend/ZendCodingStandard.php -------------------------------------------------------------------------------- FOUND 0 ERROR(S) AND 2 WARNING(S) AFFECTING 2 LINE(S) -------------------------------------------------------------------------------- 18 | WARNING | Line exceeds 85 characters; contains 100 characters 33 | WARNING | Line exceeds 85 characters; contains 104 characters -------------------------------------------------------------------------------- FILE: /home/gsherwood/PHP_CodeSniffer/CodeSniffer/Standards/Zend/Tests -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 1 | ERROR | An error occurred during processing; checking has been aborted. The | | error message was: | | RecursiveDirectoryIterator::__construct(/home/gsherwood/PHP_CodeSniffer/CodeSniffer/Standards/Zend/Tests): | | failed to open dir: Permission denied --------------------------------------------------------------------------------