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

Uncaught RuntimeException when phpcbf fails to fix files #1615

Closed
kirtangajjar opened this issue Aug 16, 2017 · 12 comments
Closed

Uncaught RuntimeException when phpcbf fails to fix files #1615

kirtangajjar opened this issue Aug 16, 2017 · 12 comments
Milestone

Comments

@kirtangajjar
Copy link

I tried to run phpcs on my file and it gave me this output:

PHPCBF RESULT SUMMARY
--------------------------------------------------------------------------------------------------------------------
FILE                                                                                                FIXED  REMAINING
--------------------------------------------------------------------------------------------------------------------
/opt/lampp/htdocs/wptest/web/app/plugins/rtcamp-slideshow-assignment/rtcamp-slideshow-script.js     FAILED TO FIX
--------------------------------------------------------------------------------------------------------------------
A TOTAL OF 362 ERRORS WERE FIXED IN 1 FILE
--------------------------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
--------------------------------------------------------------------------------------------------------------------

Time: 1.22 secs; Memory: 10Mb

When I increased the verbosity, It gave me this output:

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: ob_end_clean(): failed to delete buffer. No buffer to delete in /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Fixer.php on line 206 in /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:557
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Runner->handleErrors(8, 'ob_end_clean():...', '/home/kirtan/.c...', 206, Array)
#1 /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Fixer.php(206): ob_end_clean()
#2 /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(48): PHP_CodeSniffer\Fixer->fixFile()
#3 /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Reporter.php(262): PHP_CodeSniffer\Reports\Cbf->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), false, 204)
#4 /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(606): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile), Object(PHP_CodeSniffer\Config))
#5 /home/kirtan/. in /home/kirtan/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 557
@gsherwood
Copy link
Member

Are you able to provide the file so I can try and replicate the error. Or a smaller section of the file that reproduces the error?

@kirtangajjar
Copy link
Author

@gsherwood Weird, I tried doing it couple of more times and the issue just disappeared. No idea why :/

@gsherwood
Copy link
Member

If it comes back and you can provide a bit of code to replicate, please post it and I'll take a look.

@kirtangajjar
Copy link
Author

@gsherwood Sure :)

@jrfnl
Copy link
Contributor

jrfnl commented Aug 30, 2017

I've just run into what looks to be the same error:

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: ob_end_clean(): failed to delete
buffer. No buffer to delete in phpcs\src\Fixer.php on line 206 in phpcs\src\Runner.php on line 557

PHP_CodeSniffer\Exceptions\RuntimeException: ob_end_clean(): failed to delete buffer. No buffer to delete in phpcs\src\Fixer.php on line 206 in phpcs\src\Runner.php on line 557

Call Stack:
    0.0010     348904   1. {main}() phpcs\bin\phpcbf:0
    0.0060     509440   2. PHP_CodeSniffer\Runner->runPHPCBF() phpcs\bin\phpcbf:18
    1.8771    4312272   3. PHP_CodeSniffer\Runner->run() phpcs\src\Runner.php:193
    2.0021    4630000   4. PHP_CodeSniffer\Runner->processFile() phpcs\src\Runner.php:397
   28.9887   10430208   5. PHP_CodeSniffer\Reporter->cacheFileReport() phpcs\src\Runner.php:606
   28.9887   10448288   6. PHP_CodeSniffer\Reports\Cbf->generateFileReport() phpcs\src\Reporter.php:262
   28.9887   10431856   7. PHP_CodeSniffer\Fixer->fixFile() phpcs\src\Reports\Cbf.php:48
  128.7754   10987624   8. ob_end_clean() phpcs\src\Fixer.php:206
  128.7754   10988808   9. PHP_CodeSniffer\Runner->handleErrors() phpcs\src\Fixer.php:206

I've been able to consistently reproduce this on a file which runs into a fixer conflict using the following ruleset:

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
	<description>Apply WordPress Coding Standards to all Core files</description>

	<rule ref="WordPress-Core" />
	<rule ref="WordPress.CodeAnalysis.EmptyStatement"/>

	<arg name="extensions" value="php" />

	<!-- Show sniff codes in all reports -->
	<arg value="ps" />
</ruleset>

in combination with the following command:

phpcbf -vv ./src/wp-admin/includes/ms.php --standard=phpcs5.xml

The file I was trying to fix can be found here:
https://github.com/aaronjorbin/develop.wordpress/blob/master/src/wp-admin/includes/ms.php

The fixer conflict is a different issue which I will be looking into, the fatal error being thrown is why I'm reporting it.

@jrfnl
Copy link
Contributor

jrfnl commented Aug 30, 2017

As a side-note: it seems the new line is missing before the "* fixed 1 violations, starting loop 47 *" phrase.

@gsherwood gsherwood reopened this Aug 31, 2017
@progsmile
Copy link

progsmile commented Sep 4, 2017

Having the same issue as @jrfnl has, with phpcbf. @gsherwood please help)

Command: vendor/bin/phpcbf core/ServiceProviders/BladeServiceProvider.php -vvv -p --standard=resources/codestyle/ruleset.xml

Error and Stack trace:
PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: ob_end_clean(): failed to delete buffer. No buffer to delete in /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Fixer.php on line 206 in /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Runner.php:557 Stack trace: #0 [internal function]: PHP_CodeSniffer\Runner->handleErrors(8, 'ob_end_clean():...', '/home/imba/Prog...', 206, Array) #1 /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Fixer.php(206): ob_end_clean() #2 /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(48): PHP_CodeSniffer\Fixer->fixFile() #3 /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Reporter.php(262): PHP_CodeSniffer\Reports\Cbf->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), false, 151) #4 /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Runner.php(606): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile), Object(PHP_CodeSnif in /home/imba/Progs/books-site/vendor/squizlabs/php_codesniffer/src/Runner.php on line 557

File to fix:

<?php

namespace Core\ServiceProviders;

use Blade;
use Illuminate\Support\ServiceProvider;


class BladeServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Blade::directive('pushonce', function ($expression) {
            $domain = explode(':', trim(substr($expression, 1, -1)));
            $push_name = $domain[0];
            $push_sub = $domain[1];
            $isDisplayed = '__pushonce_'.$push_name.'_'.$push_sub;

            return "<?php if(!isset(\$__env->{$isDisplayed})): \$__env->{$isDisplayed} = true; \$__env->startPush('{$push_name}'); ?>";
        });

        Blade::directive('endpushonce', function ($expression) {
            return '<?php $__env->stopPush(); endif; ?>';
        });
    }
}

php versions: 7.0.18, and 7.1.4

@gsherwood gsherwood changed the title Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: ob_end_clean() Uncaught RuntimeException when phpcbf fails to fix files Sep 5, 2017
@gsherwood gsherwood added this to the 3.1.0 milestone Sep 5, 2017
@gsherwood
Copy link
Member

I've committed a change that I think fixes this. The ob_end_clean() line was already muted, so that code may get run with an open or closed buffer. I've changed to code to actually check the buffer state now, which has fixed the test case @jrfnl submitted.

If anyone finds additional test cases, please post them (I'll need your ruleset as well) and I'll take a look. Otherwise, I think this is now fixed so I'll close it off.

@jrfnl
Copy link
Contributor

jrfnl commented Sep 6, 2017

@gsherwood Thanks for that. I will let you know if I run into this again, but the fix looks good to me. 🤞

@progsmile
Copy link

@gsherwood Now it's working, Thanks!))

@divined
Copy link

divined commented Sep 19, 2018

Drupal\Sniffs\Arrays\ArraySniff (line 234) replaced token 8467 (T_DOUBLE_QUOTED_STRING) "··············································································································································································································································································································var·addthis_config·=·addthis_config||{};\n" => "····················································································································································································································································································································var·addthis_config·=·addthis_config||{};\n"
Drupal\Sniffs\Arrays\ArraySniff (line 234) replaced token 8468 (T_DOUBLE_QUOTED_STRING) "··············································································································································································································································································································addthis_config.lang·=·'$id';\n" => "····················································································································································································································································································································addthis_config.lang·=·'$id';\n"
Drupal\Sniffs\Arrays\ArraySniff (line 234) replaced token 8469 (T_DOUBLE_QUOTED_STRING) "············································································································································································································································································································"" => "··················································································································································································································································································································""
    => Fixing file: 3/23 violations remaining [made 50 passes]...   * fixed 3 violations, starting loop 51 *
*** Reached maximum number of loops with 3 violations left unfixed ***

@b-hayes
Copy link

b-hayes commented Dec 20, 2019

Im getting what might be a similar problem. I run on a specific file and no changes take effect with output:

-------------------------------------------------------------------------------------------
A TOTAL OF 30 ERRORS WERE FIXED IN 1 FILE
-------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
-------------------------------------------------------------------------------------------

Time: 817ms; Memory: 10MB

I ran with -vvv and chucked it in a file if that helps at all
phpcbf.log

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

No branches or pull requests

6 participants