feat: Do not swallow exceptions when scoping#869
Merged
theofidry merged 4 commits intohumbug:mainfrom Nov 1, 2023
Merged
Conversation
Closes humbug#847. Afer reviewing the linked issue, I think a better way to handle errors is to leave alone non valid PHP files (i.e. files that PHP-Parser could not parse) but otherwise fail. This can cause problems however, I suspect mostly during tests, where one may want to try the final scopped result depsite a failure. For this reason, a new option `--continue-on-failure` has been added to the `add-prefix` command. The option `--stop-on-failure` has now been deprecated and will be removed a future version.
theofidry
added a commit
to theofidry/php-scoper
that referenced
this pull request
Mar 2, 2026
This code was introduced in humbug#869 and the intent was to make PHP-Scoper fail when encountering any PHP-Parser parsing exception by default. Unfortunately the code introduced did not correctly translate this intent, this PR fixes that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #847.
As reported in #847, the current strategy is not ideal: if a failure occurs, the file is preserved. You can only see that there was a failure by paying attention to the output or having a more verbose output, unless you pass the
--stop-on-failureoption.I think historically it has been that way because in the early days of PHP-Scoper, a failure was non infrequent and it was very frustrating to not be able to examine the result despite the failure.
The tool is now more robust and the only exception that I can see regularly coming still is invalid PHP code (e.g. when it is a template). As such, this PR proposes to:
--stop-on-failurewas always provided).--continue-on-failure.The option
--stop-on-failurehas now been deprecated and will be removed a future version as it is now useless.