mokkabonna / inquirer-autocomplete-prompt

Autocomplete prompt for inquirer
ISC License
350 stars 82 forks source link

Handling errors #152

Open N1ark opened 1 year ago

N1ark commented 1 year ago

I've been using the plugin, and noticed that it doesn't seem possible to properly catch errors thrown within the source async function to allow for a graceful exit with this.error if something goes wrong. No error message is printed either, and calling this.error inside the async function doesn't work either.

Is there something I missed?

Example code:

try {
  await inquirer
    .prompt([
      {
        type: "autocomplete",
        name: "test",
        message: "Will quit",
        source: async () => { throw Error() },
      },
    ])
    .catch(() => console.log("This is never printed"));
} finally {
  console.log("This is never printed");
}
mokkabonna commented 9 months ago

Yeah that should have been handled better. In the newer inquirer-autocomplete-standalone package it is handled and presented as an error if it fails.

image

mokkabonna commented 9 months ago

Not sure why I never implemented that, I guess I never had the problem myself so forgot/ignored, and nobody else mentioned it either until now :)

N1ark commented 9 months ago

Nice ! Yeah understandable hahah, thanks for implementing it :D