Skip to content

Config: show user friendly error message when ini change failed #1024

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

Merged
merged 1 commit into from
Apr 18, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 17, 2025

Description

Inspired by discussion #415.

Previously, when a PHP ini option which cannot be changed at runtime was passed to PHPCS, it would be silently ignored (by PHP, PHPCS would still try to handle it, but would not report that PHP did not change the value).

This commit changes that behaviour by adding a new "ERROR: Ini option %s cannot be set at runtime" error to alert the end-user to the fact that they are passing a PHP ini option which PHPCS cannot change.

The new error will be thrown both when the user passes the invalid ini setting via the command line, as well as when it is passed via a custom ruleset.

The behaviour when trying to change an ini setting which doesn't exist (typo, extension not available) is unchanged. In that case, the ini directive will still be silently ignored.

Includes unit tests to safeguard the new behaviour.

Also note: when this error occurs due to an invalid setting being passed via a ruleset, the error will be thrown directly and not collected via the MessageCollector. This is due to the error coming from the Config class. Once the MessageCollector would be implemented in the Config class, this can potentially be changed.

Suggested changelog entry

Added:
An error will be shown when attempting to change an unchangable PHP ini setting using -d option[=value] or via the ruleset with <ini name=...>.
- Previously, this was silently ignored.
- Attempting to change non-existent ini settings (typo, extension not loaded) will continue to be silently ignored.

Related issues/external references

Closes #416

@jrfnl jrfnl added this to the 4.0.0 milestone Apr 17, 2025
@jrfnl jrfnl force-pushed the phpcs-4.0/feature/416-improve-ini-set-error-handling branch from 459dc12 to 7f91c5c Compare April 18, 2025 10:51
@jrfnl
Copy link
Member Author

jrfnl commented Apr 18, 2025

Made some documentation tweaks + fixed an incorrect test assertion and improve the tearDown() method. Will merge once the build has passed again.

Inspired by discussion 415.

Previously, when a PHP ini option which cannot be changed at runtime was passed to PHPCS, it would be silently ignored (by PHP, PHPCS would still try to handle it, but would not report that PHP did not change the value).

This commit changes that behaviour by adding a new "ERROR: Ini option %s cannot be set at runtime" error to alert the end-user to the fact that they are passing a PHP ini option which PHPCS cannot change.

The new error will be thrown both when the user passes the invalid ini setting via the command line, as well as when it is passed via a custom ruleset.

The behaviour when trying to change an ini setting which _doesn't exist_ (typo, extension not available) is unchanged. In that case, the ini directive will still be silently ignored.

Includes unit tests to safeguard the new behaviour.

Closes 416

Also note: when this error occurs due to an invalid setting being passed via a ruleset, the error will be thrown directly and not collected via the `MessageCollector`. This is due to the error coming from the `Config` class.
Once the `MessageCollector` would be implemented in the `Config` class, this can potentially be changed.
@jrfnl jrfnl force-pushed the phpcs-4.0/feature/416-improve-ini-set-error-handling branch from 7f91c5c to 09a96d9 Compare April 18, 2025 13:17
@jrfnl jrfnl merged commit 04f4286 into 4.x Apr 18, 2025
60 checks passed
@jrfnl jrfnl deleted the phpcs-4.0/feature/416-improve-ini-set-error-handling branch April 18, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant