Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporter throws exception when it can't create a file #1992

Closed
designermonkey opened this issue Apr 14, 2018 · 4 comments
Closed

Reporter throws exception when it can't create a file #1992

designermonkey opened this issue Apr 14, 2018 · 4 comments
Milestone

Comments

@designermonkey
Copy link

phpcs --report=json -q -s --encoding=UTF-8 --standard=/blah/blah/phpcs.xml --error-severity=5 --warning-severity=5 --stdin-path=/blah/blah/src/Command/Command.php

PHP Warning:  file_put_contents(doc/codesniffer.xml): failed to open stream: No such file or directory in phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Reporter.php on line 2
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs:0
PHP   2. PHP_CodeSniffer\Runner->runPHPCS() /usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs:6
PHP   3. PHP_CodeSniffer\Runner->run() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Runner.php:2
PHP   4. PHP_CodeSniffer\Reporter->__construct() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Runner.php:2
PHP   5. file_put_contents() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Reporter.php:2

Warning: file_put_contents(doc/codesniffer.xml): failed to open stream: No such file or directory in phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Reporter.php on line 2

Call Stack:
    0.0004     392528   1. {main}() /usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs:0
    0.0048     743600   2. PHP_CodeSniffer\Runner->runPHPCS() /usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs:6
    0.2503    3667632   3. PHP_CodeSniffer\Runner->run() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Runner.php:2
    0.2507    3718464   4. PHP_CodeSniffer\Reporter->__construct() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Runner.php:2
    0.2515    3767816   5. file_put_contents() phar:///usr/local/Cellar/php-code-sniffer/3.2.3/bin/phpcs/src/Reporter.php:2

If I create the folder, it works. Can CodeSniffer be made to ensure the directory exists before trying to use it? Surely better than throwing an exception.

@gsherwood
Copy link
Member

When I use --report-file on the command line, or include the report file option using the <arg> tag in my standard, I get this output from PHPCS:

ERROR: The specified report file path "doc/codesniffer.xml" points to a non-existent directory

But I can replicate the issue if using something like --report-json=doc/codesniffer.xml

I'll work on fixing that exception up, but please let me know if you are replicating in a different way.

@gsherwood gsherwood added this to the 3.3.0 milestone Apr 17, 2018
gsherwood added a commit that referenced this issue Apr 17, 2018
…rtType]=/path/to/report CLI option no longer throws an exception (ref #1992)
@gsherwood
Copy link
Member

I've committed a change to print a friendly error message for the scenario I list above. I'll leave this in feedback in case you've got different replication steps.

@designermonkey
Copy link
Author

Thanks for the help, I'll take a look asap.

@gsherwood
Copy link
Member

I'm going to assume this is done now, but please let me know if you find more problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants