Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exceptions in WP_CLI::error_to_string() method #5331

Merged
merged 3 commits into from Feb 18, 2020

Conversation

chesio
Copy link
Contributor

@chesio chesio commented Dec 16, 2019

Fixes #5267.

Note: I don't know if returning $e->getMessage() or converting exception to string is preferred. PR does the former.

@chesio chesio requested a review from a team as a code owner December 16, 2019 14:16
@@ -1004,6 +1004,10 @@ public static function error_to_string( $errors ) {
return $message;
}
}

if ( $errors instanceof \Exception ) {
return $errors->getMessage();
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -1004,6 +1004,10 @@ public static function error_to_string( $errors ) {
return $message;
}
}

if ( $errors instanceof \Exception ) {
Copy link
Member

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+.

Copy link
Contributor Author

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 :)

@chesio
Copy link
Contributor Author

chesio commented Jan 30, 2020

Hi @schlessera, sorry it took me so long - I've made the changes as requested/suggested.

@schlessera schlessera merged commit 6f5e81f into wp-cli:master Feb 18, 2020
@schlessera schlessera changed the title Support exceptions in WP_CLI::error_to_string method Support exceptions in WP_CLI::error_to_string() method Feb 18, 2020
@schlessera schlessera added this to the 2.5.0 milestone Feb 18, 2020
@schlessera
Copy link
Member

Thanks for the PR, @chesio !

@schlessera
Copy link
Member

Created new issue #5356 as a result of seeing the implementation here.

@chesio chesio deleted the issue-5267 branch February 18, 2020 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error_to_string() should support exceptions too
2 participants