Support exceptions in WP_CLI::error_to_string() method#5331
Merged
schlessera merged 3 commits intowp-cli:masterfrom Feb 18, 2020
Merged
Support exceptions in WP_CLI::error_to_string() method#5331schlessera merged 3 commits intowp-cli:masterfrom
WP_CLI::error_to_string() method#5331schlessera merged 3 commits intowp-cli:masterfrom
Conversation
schlessera
requested changes
Jan 2, 2020
php/class-wp-cli.php
Outdated
| } | ||
|
|
||
| if ( $errors instanceof \Exception ) { | ||
| return $errors->getMessage(); |
Member
There was a problem hiding this comment.
It might make sense to also print the concrete class of the exception, as that is often the most important distinction amongst exceptions.
Contributor
Author
There was a problem hiding this comment.
I prefixed the error message with a class name.
php/class-wp-cli.php
Outdated
| } | ||
| } | ||
|
|
||
| if ( $errors instanceof \Exception ) { |
Member
There was a problem hiding this comment.
We should check for Throwable as well, as that is the base interface to catch starting with PHP 7+.
Contributor
Author
There was a problem hiding this comment.
Nice catch, I learned something new :)
Contributor
Author
|
Hi @schlessera, sorry it took me so long - I've made the changes as requested/suggested. |
schlessera
approved these changes
Feb 18, 2020
WP_CLI::error_to_string() method
Member
|
Thanks for the PR, @chesio ! |
Member
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5267.
Note: I don't know if returning $e->getMessage() or converting exception to string is preferred. PR does the former.