Skip to content

Include error backtrace in fatal error handler message#6291

Merged
swissspidy merged 2 commits intomainfrom
fix/shutdown-handler
Mar 27, 2026
Merged

Include error backtrace in fatal error handler message#6291
swissspidy merged 2 commits intomainfrom
fix/shutdown-handler

Conversation

@swissspidy
Copy link
Copy Markdown
Member

Before:

Error: There has been a critical error on this website.

This error may have been caused by a theme or plugin.
To skip all plugins and themes, run the command again with:
  --skip-plugins --skip-themes

After:

Error: There has been a critical error on this website.

Uncaught Error: Call to undefined method WP_Error::getDataUri() in /path/to/ai-command/src/AI_Command.php:500
Stack trace:
#0 /path/to/ai-command/src/AI_Command.php(190): WP_CLI\AI\AI_Command->generate_image(Object(WP_AI_Client_Prompt_Builder), Array)
#1 [internal function]: WP_CLI\AI\AI_Command->generate(Array, Array)
#2 /path/to/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(113): call_user_func(Array, Array, Array)
#3 [internal function]: WP_CLI\Dispatcher\CommandFactory::{closure:WP_CLI\Dispatcher\CommandFactory::create_subcommand():104}(Array, Array)
#4 /path/to/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(762): call_user_func(Object(Closure), Array, Array)
#5 /path/to/wp-cli/wp-cli/php/WP_CLI/Runner.php(622): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
#6 /path/to/wp-cli/wp-cli/php/WP_CLI/Runner.php(651): WP_CLI\Runner->run_command(Array, Array)
#7 /path/to/wp-cli/wp-cli/php/WP_CLI/Runner.php(1677): WP_CLI\Runner->run_command_and_exit()
#8 /path/to/scaffold-package-command/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(31): WP_CLI\Runner->start()
#9 /path/to/wp-cli/wp-cli/php/bootstrap.php(87): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#10 /path/to/wp-cli/wp-cli/php/wp-cli.php(35): WP_CLI\bootstrap()
#11 /path/to/wp-cli/wp-cli/php/boot-fs.php(17): require_once('/Users/pascalb/...')
#12 {main}
  thrown

This error may have been caused by a theme or plugin.
To skip all plugins and themes, run the command again with:
  --skip-plugins --skip-themes

@swissspidy swissspidy requested a review from a team as a code owner March 27, 2026 11:07
Copilot AI review requested due to automatic review settings March 27, 2026 11:07
@github-actions
Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/ShutdownHandler.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates WP-CLI’s fatal error messaging so users see more diagnostic detail (the underlying PHP fatal error) alongside the existing plugin/theme skip rerun suggestions.

Changes:

  • Append the raw fatal error message (error_get_last()['message']) to the WP-CLI fatal error output.
  • Tighten the $error phpdoc to an array-shape for improved static analysis.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the PHPDoc type hint for the error parameter in ShutdownHandler.php and appends the error message to the critical error notification. I have suggested sanitizing the appended error message using wp_strip_all_tags to ensure consistent and clean output in the terminal.

@swissspidy swissspidy added this to the 3.0.0 milestone Mar 27, 2026
@swissspidy swissspidy merged commit 71de10f into main Mar 27, 2026
68 of 69 checks passed
@swissspidy swissspidy deleted the fix/shutdown-handler branch March 27, 2026 12:10
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.

2 participants