From d8e6feea9857bf6e5a68f6f09ec750dacf63855a Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 10 Oct 2016 16:34:01 -0700 Subject: [PATCH 1/2] Provide more verbosity in `wp_die()` handler This gives the end user more detail when a database connection fails, instead of a cryptic message. --- features/db.feature | 2 +- features/framework.feature | 4 ++-- php/utils-wp.php | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/features/db.feature b/features/db.feature index 5c33e6d000..ae97e59333 100644 --- a/features/db.feature +++ b/features/db.feature @@ -9,7 +9,7 @@ Feature: Perform database operations Then STDOUT should be empty And STDERR should be: """ - Error: Can’t select database + Error: Can’t select database. We were able to connect to the database server (which means your username and password is okay) but not able to select the `wp_cli_test` database. """ When I run `wp db create` diff --git a/features/framework.feature b/features/framework.feature index 83732a03ea..701d0027c9 100644 --- a/features/framework.feature +++ b/features/framework.feature @@ -195,11 +195,11 @@ Feature: Load WP-CLI When I try `wp --require=invalid-host.php option get home` Then STDERR should contain: """ - Error: Error establishing a database connection + Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localghost`. This could mean your host’s database server is down. """ When I try `wp --require=invalid-host.php --require=wp-debug.php option get home` Then STDERR should contain: """ - Error: Error establishing a database connection + Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localghost`. This could mean your host’s database server is down. """ diff --git a/php/utils-wp.php b/php/utils-wp.php index 416fa28510..2b5ffbd388 100644 --- a/php/utils-wp.php +++ b/php/utils-wp.php @@ -54,11 +54,20 @@ function wp_die_handler( $message ) { $message = $message->get_error_message(); } - $message = trim( $message ); - if ( preg_match( '|^\

(.+?)

|', $message, $matches ) ) { - $message = $matches[1]; + $original_message = $message = trim( $message ); + if ( preg_match( '|^\

(.+?)

|', $original_message, $matches ) ) { + $message = $matches[1] . '.'; + } + if ( preg_match( '|\

(.+?)

|', $original_message, $matches ) ) { + $message .= ' ' . $matches[1]; } + $search_replace = array( + '' => '`', + '' => '`', + ); + $message = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $message ); + $message = strip_tags( $message ); $message = html_entity_decode( $message, ENT_COMPAT, 'UTF-8' ); \WP_CLI::error( $message ); From 2a12e9a1c4e57d1cf6543b1c2294b4a2132cc22c Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 11 Oct 2016 06:34:42 -0700 Subject: [PATCH 2/2] Less precise check for WP 3.7.11 --- features/framework.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/framework.feature b/features/framework.feature index 701d0027c9..3e1751e99f 100644 --- a/features/framework.feature +++ b/features/framework.feature @@ -195,11 +195,11 @@ Feature: Load WP-CLI When I try `wp --require=invalid-host.php option get home` Then STDERR should contain: """ - Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localghost`. This could mean your host’s database server is down. + Error: Error establishing a database connection. """ When I try `wp --require=invalid-host.php --require=wp-debug.php option get home` Then STDERR should contain: """ - Error: Error establishing a database connection. This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `localghost`. This could mean your host’s database server is down. + Error: Error establishing a database connection. """