Skip to content

Commit

Permalink
Add break to prevent endless recursion loop
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Oct 28, 2023
1 parent 878d359 commit 630fa09
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 630fa09

Please sign in to comment.