Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

skip question when error in choices function

Open GiladShoham opened this issue 6 years ago • 3 comments

Hi,

I have a question with choices as function. This function fetches answers from a remote server which might be unavailable or the query to the remote is invalid. This question is part of a qustions array. I want to catch an error in the function of the choice (not a problem), write it to the user. and skip the question and moving to the next one. I can put the check in the when, but it's a time-consuming check and I don't want to do it twice both in when and in choices. Is there any way to handle this? or just by opt-out from the array way of prompting?

Thanks.

GiladShoham avatar Aug 01 '19 16:08 GiladShoham

How about you do this processing before calling inquirer.prompt()?

SBoudrias avatar Aug 11 '19 09:08 SBoudrias

I can't do it before because the choices are based on previous answers. I ended up putting the logic of the choices inside the when and if there was an error I returned false. If it worked I just store the choices in a var and just use it in the choices. You can see the full code here: https://github.com/teambit/bit/blob/master/src/interactive/commands/init-interactive.js#L51 It was great if I would have an API like this.skip function inside the choices function.

GiladShoham avatar Aug 11 '19 11:08 GiladShoham

@GiladShoham "page not found"

Aid19801 avatar Mar 02 '20 12:03 Aid19801