Skip to content
New issue

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

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

Already on GitHub? # to your account

Error in transformer when using default exits silently (version 8) #1247

Open
robations opened this issue Jun 7, 2023 · 1 comment
Open
Labels

Comments

@robations
Copy link

An error thrown from a transformer (after a default value is applied) gets swallowed and the CLI app quits, which makes debugging difficult.

Some sample code:

const Inquirer = require("inquirer");

(async () => {
    try {
        await Inquirer.prompt([
            {
                type: "input",
                message: "Foo quotient",
                name: "foo",
                transformer: (x) => {
                    if (x === 1) {
                        throw new Error("failing because of the reason");
                    }
                    return x;
                },
                default: 1,
            },
        ]);

        console.log("Done");
    } catch (e) {
        console.error("An _expected_ error", e);
    }
})();

In this example, when no input is offered by the user, I would expect:

  • the default is applied (1)
  • error is thrown
  • catch block outputs error

But instead the program silently quits (no error, no "Done" logged).

(I'm not sure if version 8 is actively maintained but unable to switch to ES modules at present.)

@mastrzyz
Copy link
Contributor

@SBoudrias something like this? #1265

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

No branches or pull requests

3 participants