diff --git a/packages/framework/src/Console/Concerns/BetterChoiceHelper.php b/packages/framework/src/Console/Concerns/BetterChoiceHelper.php index 772eb1aefde..e42d5d0774d 100644 --- a/packages/framework/src/Console/Concerns/BetterChoiceHelper.php +++ b/packages/framework/src/Console/Concerns/BetterChoiceHelper.php @@ -5,6 +5,7 @@ namespace Hyde\Console\Concerns; use Closure; +use RuntimeException; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Output\NullOutput; @@ -53,6 +54,11 @@ protected function betterChoice(string $question, array $choices, int|string $de $selection = $choices[$answer] ?? null; if ($selection === null) { + // High enough to not impact normal usage, but low enough to break loops + if ($this->retryCount > 30) { + throw new RuntimeException('Maximum retries exceeded'); + } + $this->retryCount++; $this->output->error(sprintf('Invalid option "%s"', $answer)); $this->betterChoice(...func_get_args());