Skip to content

Fixes exception bubbling for php7 #39

New issue

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

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

Already on ? Sign in to your account

Merged
merged 1 commit into from
May 10, 2017

Conversation

chrishulton
Copy link
Contributor

@chrishulton chrishulton commented May 10, 2017

I noticed some builds printing fatal errors, but exiting with status 0 and "Found 0 issues."

[DEBUG] phpmd:stable engine stderr: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PHPMD\PHPMD::setFileExtensions() must be of the type array, null given, called in /usr/src/app/Runner.php on
line 101 and defined in /usr/src/app/vendor/phpmd/phpmd/src/main/php/PHPMD/PHPMD.php:136
Stack trace:
#0 /usr/src/app/Runner.php(101): PHPMD\PHPMD->setFileExtensions(NULL)
...
  thrown in /usr/src/app/vendor/phpmd/phpmd/src/main/php/PHPMD/PHPMD.php on line 136

Analysis complete! Found 0 issues.

It looks like this is because the exception flow changed in php7:
https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/
http://php.net/manual/en/language.errors.php7.php

The main point being there is now a separation between Exception and Error objects:

Throwable may be used in try/catch blocks to catch both Exception and Error objects (or any possible future exception types).

interface Throwable
    |- Exception implements Throwable
        |- ...
    |- Error implements Throwable
        |- TypeError extends Error
        ...

Rescuing the globally namespaced \Throwable will also rescue Errors such as this TypeError. I can verify this leads to the correct behavior (the error message is also printed in our format from the catch block):

Running phpmd: Done!
error: (CC::Analyzer::Engine::EngineFailure) engine phpmd:stable failed with status 1 and stderr
Exception: Argument 1 passed to PHPMD\PHPMD::setFileExtensions() must be of the type array, null given, called in /usr/src/app/Runner.php on line 101 in /usr/src/app/vendor/phpmd/phpmd/src/main/php/PHPMD/PHPMD.php
#0 /usr/src/app/Runner.php(101): PHPMD\PHPMD->setFileExtensions(NULL)
...

I will make the same fix in phpcodesniffer assuming this fix goes well.

@chrishultonchrishulton merged commit de763ff into master May 10, 2017
@chrishultonchrishulton deleted the chris/php7-exception-bubbling-fix branch May 10, 2017 20:06
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants