Support exceptions in `WP_CLI::error_to_string()` method by chesio · Pull Request #5331 · wp-cli/wp-cli
Fixes #5267.
Note: I don't know if returning $e->getMessage() or converting exception to string is preferred. PR does the former.
| } | ||
|
|
||
| if ( $errors instanceof \Exception ) { | ||
| return $errors->getMessage(); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to also print the concrete class of the exception, as that is often the most important distinction amongst exceptions.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefixed the error message with a class name.
| } | ||
| } | ||
|
|
||
| if ( $errors instanceof \Exception ) { |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check for Throwable as well, as that is the base interface to catch starting with PHP 7+.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I learned something new :)
Hi @schlessera, sorry it took me so long - I've made the changes as requested/suggested.
schlessera
changed the title
Support exceptions in WP_CLI::error_to_string method
Support exceptions in WP_CLI::error_to_string() method
Created new issue #5356 as a result of seeing the implementation here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters