Respect WP_DEBUG/WP_DEBUG_DISPLAY instead of unconditionally overriding display_errors by Copilot · Pull Request #6284 · wp-cli/wp-cli · GitHub
Skip to content

Respect WP_DEBUG/WP_DEBUG_DISPLAY instead of unconditionally overriding display_errors#6284

Draft
Copilot wants to merge 9 commits into
mainfrom
copilot/respect-wp-debug-setting
Draft

Respect WP_DEBUG/WP_DEBUG_DISPLAY instead of unconditionally overriding display_errors#6284
Copilot wants to merge 9 commits into
mainfrom
copilot/respect-wp-debug-setting

Conversation

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor
  • Fix wp_debug_mode() in php/utils-wp.php to respect WP_DEBUG/WP_DEBUG_DISPLAY instead of always overriding display_errors to stderr
  • Fix Runner.php: make the post-WordPress-load error reporting conditional in Behat test environment, and explicitly suppress both display_errors and log_errors after WP loads when errors should be hidden
  • Fix Behat tests: use When I try instead of When I run for scenarios that produce STDERR output (WP_DEBUG=true and --debug scenarios)
  • Add Behat tests covering all 4 scenarios:
    • WP_DEBUG=true without --debug shows errors on STDERR
    • WP_DEBUG=false without --debug hides errors on STDERR
    • WP_DEBUG=true + WP_DEBUG_DISPLAY=false hides errors on STDERR
    • --debug always shows errors on STDERR regardless of WP_DEBUG
  • Run PHPCS, PHPStan, lint checks - all pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Respect WP_DEBUG instead of overriding</issue_title>
<issue_description>Currently the value of display_errors is overridden by \Utils\wp_debug_mode(), but I would expect WP_CLI to respect the value set by WP_DEBUG and \wp_debug_mode() instead.

It sounds like there may have once been a reason for overriding it, but it's not known anymore.

In my experience, having it overridden is a hassle, because when I'm writing commands I don't have notice/warning/error messages easily available. In many cases, it might not even be obvious that an error occurred at all. So I have to manually check log files or use a fragile workaround to restore the original settings.

I'd be happy to work on a PR if it's decided that this behavior should be removed.

Background information:

php/utils-wp.php#L26
cb57cc0
#786
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber > Currently the value of display_errors is overridden by `\Utils\wp_debug_mode()`, but I would expect WP_CLI to respect the value set by `WP_DEBUG` and `\wp_debug_mode()` instead.

Sorry if I'm being a bit dense, but I'm still not sure what the problem is. Can you provide a more detailed example of how this is a problem, what the current behavior is, and what you'd expect the behavior to be?

@danielbachhuber What would you think about this? 1. If `WP_DEBUG=true`, then WP-CLI defaults to displaying errors when `--debug` is and isn't included. If `--no-debug` is passed, then WP-CLI silences errors. 2. If `WP_DEBUG=false` or isn't set, the WP-CLI defaults to not displaying errors. `--debug` would enable displaying errors.

It does seem somewhat erroneous for WP-CLI to quietly silence errors when WP_DEBUG is defined in wp-config.php.

@danielbachhuber > Yeah, that makes sense to me. I'll work on a PR :)

👍

It'd be good to have explicit test coverage for each of the scenarios, where we don't already.

@danielbachhuber > Yeah, that makes sense to me. I'll work on a PR :)

@iandunn Do you have a timeframe you're willing to commit to for this? Otherwise, I think this issue should be free for the first person to submit a PR.

@danielbachhuber @iandunn I added a testcase in #3372 for the behavior you described in https://github.com//issues/3220#issuecomment-236649813. The testcase passes, which isn't what I'd expect if the behavior was broken like you initially described.

Can you re-verify the original issue, and confirm there isn't additional code in your environment that might be affecting error reporting?

@danielbachhuber > Oh well, I guess I'll just consider this resolved unless I run into it again in the future. Sorry for the trouble.

No worries! Happy to look into it again if you can track down more steps to reproduce.

@swissspidy Reopening due to the comment above and the open PR. @danielbachhuber Flagging this for `contributor-day`. It seems like a couple or few people should solve it together.

I think we should solve this by:

  1. Creating documentation that captures what the expected behavior should be.
  2. Write tests for the expected behavior.
  3. Make the necessary changes to the framework.</comment_new>

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…lways overriding display_errors

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Respect WP_DEBUG instead of overriding display_errors Respect WP_DEBUG/WP_DEBUG_DISPLAY instead of unconditionally overriding display_errors Mar 20, 2026
Copilot AI requested a review from swissspidy March 20, 2026 13:40
@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

@swissspidy

This comment was marked as resolved.

… When I try for STDERR-producing scenarios

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wp-cli/wp-cli/sessions/64331e74-d930-4d27-a6ae-032b5420050a

This comment was marked as resolved.

Comment thread features/utils-wp.feature Outdated
@swissspidy

This comment was marked as resolved.

…rors should be hidden

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wp-cli/wp-cli/sessions/fbca0519-fe3c-4131-ba97-5e3c7b737e22

This comment was marked as resolved.

Copilot AI requested a review from swissspidy March 20, 2026 22:01
@swissspidy

This comment was marked as resolved.

…for WP_DEBUG_DISPLAY=false

Agent-Logs-Url: https://github.com/wp-cli/wp-cli/sessions/d3e4efd4-ee08-44f7-91f5-d28b556cd958

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

Copy link
Copy Markdown
Member

@copilot fix failing tests

- flags.feature: Update "Debug run" scenario (@less-than-php-8) to expect
  empty STDERR (no PHP notice) when WP_DEBUG=false and --debug is not passed.
  The old test expected the undefined-constant notice unconditionally, but
  with the new behavior it is correctly suppressed. The second block (with
  --debug) is unchanged and still verifies the notice appears on STDERR.

- wp-config.feature: Replace `STDERR should contain: TEST_CONFIG_OVERRIDE`
  (which relied on a PHP notice only produced on PHP < 8) with
  `STDOUT should not contain: TEST_CONFIG_OVERRIDE => success`, which
  correctly validates the negative case on both PHP 7.x and PHP 8+.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

Copilot AI commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect WP_DEBUG instead of overriding

2 participants