Skip to content

Commit e9907b3

Browse files
committed
fix(cli): guard non-interactive prompter against empty options
Add the same empty-options check to createNonInteractivePrompter's selectOne that the TTY prompter already has, preventing an out-of-bounds access if called with an empty array.
1 parent 693a6f9 commit e9907b3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/cli/interactive/prompts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ function clampIndex(index: number, optionsLength: number): number {
3030
function createNonInteractivePrompter(): Prompter {
3131
return {
3232
async selectOne<T>(opts: { options: SelectOption<T>[]; initialIndex?: number }): Promise<T> {
33+
if (opts.options.length === 0) {
34+
throw new Error('No options available for selection.');
35+
}
3336
const index = clampIndex(opts.initialIndex ?? 0, opts.options.length);
3437
return opts.options[index].value;
3538
},

0 commit comments

Comments
 (0)