Skip to content

Conversation

danielbachhuber
Copy link
Member

@danielbachhuber danielbachhuber commented Jul 24, 2023

Fixes #5240

Trying to fix this upstream is too much of a rabbit hole. Instead, let's give the user a more helpful pointer:

$ wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(599): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: An unexpected functions.php file in the themes directory may have caused this internal server error.

Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

I have to say it's quite the edge case but alas 🤷‍♂️

@@ -100,7 +100,7 @@ function wp_die_handler( $message ) {
$error_data = $message->get_error_data( 'internal_server_error' );
if ( ! empty( $error_data['error']['file'] )
&& false !== stripos( $error_data['error']['file'], 'themes/functions.php' ) ) {
$text_message = 'There was an internal server error that may have been caused by an unexpected functions.php file in the themes directory.';
$text_message = 'An unexpected functions.php file in the themes directory may have caused this internal server error.';
Copy link
Member

Choose a reason for hiding this comment

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

Oh, what about the original error message? Shouldn't that be kept and displayed as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

@schlessera I don't think the original error message is particularly helpful.

Original output

$ wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(600): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

New output

$  wp --skip-themes option get home
Fatal error: Uncaught Error: Call to undefined function genesis_register_sidebar() in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php:3
Stack trace:
#0 /Users/danielbachhuber/projects/vanilla/wp-settings.php(600): include()
#1 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1349): require('/Users/danielba...')
#2 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
#3 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#4 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#6 /Users/danielbachhuber/projects/wp-cli-dev/wp-cli/php/boot-fs.php(17): require_once('/Users/danielba...')
#7 {main}
  thrown in /Users/danielbachhuber/projects/vanilla/wp-content/themes/functions.php on line 3
Error: An unexpected functions.php file in the themes directory may have caused this internal server error.

@danielbachhuber danielbachhuber merged commit a33e0f8 into main Aug 14, 2023
@danielbachhuber danielbachhuber deleted the fix/themes-functions branch August 14, 2023 22:11
@swissspidy
Copy link
Member

@danielbachhuber Hmm looks like the automated tests for the Phar build are now failing because of this: https://github.com/wp-cli/automated-tests/actions/runs/5885136682/job/15961097291#step:14:263

@danielbachhuber
Copy link
Member Author

@swissspidy I think updating the bundle should fix wp-cli/wp-cli-bundle#566

@swissspidy
Copy link
Member

@danielbachhuber doesn't look like it, see this latest run: https://github.com/wp-cli/automated-tests/actions/runs/5903479397/job/16013536710

What am I missing?

@danielbachhuber
Copy link
Member Author

What am I missing?

@swissspidy It looks like the tests are running against the nightly Phar build, but it's not being deployed right now wp-cli/wp-cli-bundle#568

@danielbachhuber
Copy link
Member Author

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.

Top level themes/functions.php file breaks --skip-themes
3 participants