Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ public static function warning( $message ) {
* @access public
* @category Output
*
* @param string|WP_Error $message Message to write to STDERR.
* @param boolean|integer $exit True defaults to exit(1).
* @param string|WP_Error|Exception $message Message to write to STDERR.
* @param boolean|integer $exit True defaults to exit(1).
* @return null
*/
public static function error( $message, $exit = true ) {
Expand Down Expand Up @@ -976,7 +976,7 @@ public static function print_value( $value, $assoc_args = array() ) {
}

/**
* Convert a wp_error into a string
* Convert a WP_Error or Exception into a string
*
* @param mixed $errors
* @return string
Expand Down Expand Up @@ -1004,6 +1004,12 @@ public static function error_to_string( $errors ) {
return $message;
}
}

// PHP 7+: internal and user exceptions must implement Throwable interface.
// PHP 5: internal and user exceptions must extend Exception class.
if ( interface_exists( 'Throwable' ) && ( $errors instanceof \Throwable ) || ( $errors instanceof \Exception ) ) {
return get_class( $errors ) . ': ' . $errors->getMessage();
}
}

/**
Expand Down