plugin-check icon indicating copy to clipboard operation
plugin-check copied to clipboard

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

Open ernilambar opened this issue 1 year ago • 7 comments
trafficstars

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 avatar Dec 20 '23 07:12 ernilambar

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

ernilambar avatar Jan 10 '24 06:01 ernilambar

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

swissspidy avatar Jan 10 '24 08:01 swissspidy

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

ernilambar avatar Jan 10 '24 10:01 ernilambar

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

swissspidy avatar Jan 10 '24 10:01 swissspidy

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().

ernilambar avatar Jan 10 '24 10:01 ernilambar

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?

alewolf avatar Jun 13 '24 13:06 alewolf

Yes, I think it should show a warning.

davidperezgar avatar Sep 25 '24 20:09 davidperezgar