Throw exception when misusing `error_to_string()` by vsamoletov · Pull Request #5405 · wp-cli/wp-cli
Expand Up
@@ -979,6 +979,8 @@ public static function print_value( $value, $assoc_args = array() ) {
* Convert a WP_Error or Exception into a string
*
* @param mixed $errors
* @throws \InvalidArgumentException
*
* @return string
*/
public static function error_to_string( $errors ) {
Expand Down
Expand Up
@@ -1010,6 +1012,13 @@ public static function error_to_string( $errors ) {
if ( interface_exists( 'Throwable' ) && ( $errors instanceof \Throwable ) || ( $errors instanceof \Exception ) ) {
return get_class( $errors ) . ': ' . $errors->getMessage();
}
throw new \InvalidArgumentException( sprintf( "Unsupported argument type passed to WP_CLI::error_to_string(): '%s'", gettype( $errors ) ) ); }
/** Expand Down
throw new \InvalidArgumentException( sprintf( "Unsupported argument type passed to WP_CLI::error_to_string(): '%s'", gettype( $errors ) ) ); }
/** Expand Down