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

Posts: 36 πŸ§‘πŸ»β€πŸš€ - Cadet

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

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

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

  • 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

  • Posts: 36 πŸ§‘πŸ»β€πŸš€ - Cadet

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

  • Lead Spryker Solution Architect / Technical Director 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.

  • Posts: 36 πŸ§‘πŸ»β€πŸš€ - Cadet

    ah.. okay understood. Thanks again @UL6DGRULR

Welcome!

It looks like you're new here. Sign in or register to get started.