Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocompleteMultiselect errors on invalid option #418

Open
asportnoy opened this issue Jun 10, 2024 · 0 comments
Open

autocompleteMultiselect errors on invalid option #418

asportnoy opened this issue Jun 10, 2024 · 0 comments

Comments

@asportnoy
Copy link

asportnoy commented Jun 10, 2024

Describe the bug

When using an autocompleteMultiselect prompt, pressing space to select when there's no results for a filter causes a crash.

To Reproduce

Run this code:

import prompts from 'prompts';

await prompts({
    type: 'autocompleteMultiselect',
    name: 'test',
    message: 'Enter some gibberish below, then press space',
    choices: [
        {
            title: 'Foo',
            value: 'Foo',
        },
    ],
});
  1. Type some random text so no results match the filter
  2. Press space to "select" this option
  3. Error:
node:internal/readline/emitKeypressEvents:74
            throw err;
            ^

TypeError: Cannot read properties of undefined (reading 'selected')
    at AutocompleteMultiselectPrompt.handleSpaceToggle (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/autocompleteMultiselect.js:101:11)
    at AutocompleteMultiselectPrompt._ (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/autocompleteMultiselect.js:119:12)
    at ReadStream.keypress (/Users/albert/Documents/repo/node_modules/prompts/lib/elements/prompt.js:30:24)
    at ReadStream.emit (node:events:518:28)
    at emitKeys (node:internal/readline/utils:371:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36)
    at ReadStream.emit (node:events:530:35)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)

Node.js v20.12.2

Expected behavior

Likely should do nothing, but definitely shouldn't be erroring

System

  • OS: macOS Sonoma 14.5
  • Terminal: iTerm 3.5.0
  • Node version: v20.12.2

Additional context

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant