Skip to content

feat: Do not swallow exceptions when scoping#869

Merged
theofidry merged 4 commits intohumbug:mainfrom
theofidry:feat/user-patch
Nov 1, 2023
Merged

feat: Do not swallow exceptions when scoping#869
theofidry merged 4 commits intohumbug:mainfrom
theofidry:feat/user-patch

Conversation

@theofidry
Copy link
Copy Markdown
Member

@theofidry theofidry commented Nov 1, 2023

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-failure option.

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:

  • Leave the file unchanged if a PHP-Parser parsing error occurred (it is still marked as failed and appears in the logs as before).
  • Fail on any other failure (i.e. proceed as if --stop-on-failure was always provided).
  • Introduce a new counterpart option --continue-on-failure.

The option --stop-on-failure has now been deprecated and will be removed a future version as it is now useless.

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 theofidry enabled auto-merge (squash) November 1, 2023 16:14
@theofidry theofidry disabled auto-merge November 1, 2023 16:41
@theofidry theofidry merged commit fc1ac4e into humbug:main Nov 1, 2023
@theofidry theofidry deleted the feat/user-patch branch November 1, 2023 16:41
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.
theofidry added a commit that referenced this pull request Mar 2, 2026
This code was introduced in #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.

Closes #1138.
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

Successfully merging this pull request may close these issues.

Patchers don't report errors to default error handler

1 participant