WordPress / plugin-check

A repository for the new Plugin Check plugin from the WordPress Performance and Plugins Team.
https://wordpress.org/plugins/plugin-check/
GNU General Public License v2.0
242 stars 49 forks source link

Display warning if non existent parameters are passed in `--checks` and `--categories` #348

Open ernilambar opened 9 months ago

ernilambar commented 9 months ago

Proper warning message should be displayed rather than fatal error when non existent check is passed to --checks

wp plugin check hello-universe --checks=nonexistent_check

Currently it generates PHP fatal error.

Fatal error: Uncaught Exception: Check with the slug "nonexistent_check" does not exist. in /var/www/html/wp-content/plugins/plugin-check/includes/Checker/Default_Check_Collection.php:158

May be we should display warning message like

WARNING: Invalid check slug 'nonexistent_check'

We could implement similar for categories also.

wp plugin check hello-universe --categories=nonexistent_category

ernilambar commented 8 months ago

This issue is similar to https://github.com/WordPress/plugin-check/issues/360 . Would it be of worth implementing the validation here for --checks and --categories? Not a critical issue though.

cc: @swissspidy @felixarntz @mukeshpanchal27

swissspidy commented 8 months ago

I suppose we can catch any exceptions and turn them into proper error messages (not warnings)

ernilambar commented 8 months ago

I suppose we can catch any exceptions and turn them into proper error messages (not warnings)

@swissspidy Please check https://github.com/WordPress/plugin-check/pull/383

swissspidy commented 8 months ago

I was thinking more like something like this in the command class:

try {
....
} catch ( Exception $error ) {
    WP_CLI::error( $error->getMessage() );
}

We already do this in some places

ernilambar commented 8 months ago

This fatal error comes before execution reaches to CLI command class. Even when public function check( $args, $assoc_args ) in Plugin_Check_Command function is empty, this error appears. It is triggered from Plugin_Request_Utility::initialize_runner().

alewolf commented 3 months ago

When checking for a non-existent category like wp plugin check hello-universe --categories=nonexistent_category, there is no fatal error. It just doesn't run any check.

Should PCP show a warning?

davidperezgar commented 1 week ago

Yes, I think it should show a warning.