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

PHPCS can show 0 exit code when running in parallel even if child process has fatal error #3645

Merged
merged 1 commit into from
Aug 13, 2022

Conversation

enl
Copy link
Contributor

@enl enl commented Aug 9, 2022

When a child process fails, e.g. with a FatalError, it might still return empty list of errors. Although, child process failure is definitely not a thing we want to ignore.

Therefore, we check exit status of each child process and make sure parent process fails (and returns non-zero status code) as well.

When a child process fails, e.g. with a FatalError, it might still return empty list of errors. Although, child process failure is definitely not a thing we want to ignore.

Therefore, we check exit status of each child process and make sure parent process fails (and returns non-zero status code) as well.
@enl
Copy link
Contributor Author

enl commented Aug 9, 2022

A bit more details on what's the issue:

When I run phpcs in single process mode, phpcs returns 255 status code and successfully fails my Jenkins build

% vendor/bin/phpcs -standard=ci/phpcs.xml -parallel=1
..............PHP Fatal error:  Uncaught TypeError: Argument 5 passed to SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation::__construct() must be an instance of PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode or null, instance of PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode given, called in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 357 and defined in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php:31
Stack trace:
#0 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(357): SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation->__construct('@param', 1181, 1183, '$types', Object(PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode))
#1 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/Sl in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php on line 31Fatal error: Uncaught TypeError: Argument 5 passed to SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation::__construct() must be an instance of PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode or null, instance of PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode given, called in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 357 and defined in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php:31
Stack trace:
#0 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(357): SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation->__construct('@param', 1181, 1183, '$types', Object(PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode))
#1 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/Sl in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php on line 31
aleksandrpanshin@Aleksandrs-MacBook-Pro phpcs-rulesets % echo $?                                              
255

But if I do the same in parallel, then I get 0 status:

aleksandrpanshin@Aleksandrs-MacBook-Pro phpcs-rulesets % vendor/bin/phpcs -standard=ci/phpcs.xml -parallel=2
.PHP Fatal error:  Uncaught TypeError: Argument 5 passed to SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation::__construct() must be an instance of PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode or null, instance of PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode given, called in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 357 and defined in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php:31
Stack trace:
#0 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(357): SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation->__construct('@param', 1181, 1183, '$types', Object(PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode))
#1 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/Sl in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php on line 31Fatal error: Uncaught TypeError: Argument 5 passed to SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation::__construct() must be an instance of PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode or null, instance of PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode given, called in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php on line 357 and defined in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php:31
Stack trace:
#0 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php(357): SlevomatCodingStandard\Helpers\Annotation\ParameterAnnotation->__construct('@param', 1181, 1183, '$types', Object(PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode))
#1 /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/Sl in /Users/aleksandrpanshin/work/modules/phpcs-rulesets/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/Annotation/ParameterAnnotation.php on line 31
. 2 / 2 (100%)
Time: 1.4 secs; Memory: 12MBaleksandrpanshin@Aleksandrs-MacBook-Pro phpcs-rulesets % echo $?
0

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Aug 13, 2022
@gsherwood gsherwood changed the title Handle child process failing PHPCS can show 0 exit code when running in parallel even if child process has fatal error Aug 13, 2022
gsherwood added a commit that referenced this pull request Aug 13, 2022
gsherwood added a commit that referenced this pull request Aug 13, 2022
@gsherwood gsherwood merged commit 9f7cbd9 into squizlabs:master Aug 13, 2022
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Aug 13, 2022
@gsherwood
Copy link
Member

Thanks for submitted a fix for this. I simplified the logic a bit by just reusing the $success variable as this was only an issue when no errors were reported by the child process (as you said).

@gsherwood gsherwood added this to the 3.7.2 milestone Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants