What are the Slack Archives?

Itโ€™s a history of our time together in the Slack Community! Thereโ€™s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you wonโ€™t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Is there any Exception class to validate console command arguments, if argument has null /empty valu

U03KHDBS1CN
U03KHDBS1CN Posts: 36 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

Is there any Exception class to validate console command arguments, if argument has null /empty values

Comments

  • Alberto Reyer
    Alberto Reyer Posts: 690 ๐Ÿช - Explorer

    InputArgument::REQUIRED or InputOption::VALUE_REQUIRED should do the trick (https://symfony.com/doc/current/console/input.html#using-command-arguments)

  • U03KHDBS1CN
    U03KHDBS1CN Posts: 36 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    I added InputArgument::REQUIRED but once I intentionally leave it blank it throws error, I need to catch that and throw custom exception

  • U03KHDBS1CN
    U03KHDBS1CN Posts: 36 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    its a runtime exception, in console do we have any option to catch and throw custom message?

  • Alberto Reyer
    Alberto Reyer Posts: 690 ๐Ÿช - Explorer
    edited July 2022

    You can directly implement the run method, within this method you could catch the exception.
    A better way would be to implement the initialize method and do your custom validation of the input there, so you can give a graceful error message.

  • U03KHDBS1CN
    U03KHDBS1CN Posts: 36 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    ah.. okay understood. Thanks again @UL6DGRULR