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

rawlist throws unhandable rejection #1042

Closed
SanariSan opened this issue Sep 13, 2021 · 1 comment
Closed

rawlist throws unhandable rejection #1042

SanariSan opened this issue Sep 13, 2021 · 1 comment

Comments

@SanariSan
Copy link
Contributor

Node: 14.17.4
Language: pure JS (no transpilation) / TS (tsc into ES2020) (doesn't matter)

To be more accurate, rawlist throws multiple promise rejections if pressing "Enter" i.e. accepting after entering non-existing index. So, when validate error appears just press "Enter".

Moreover, you can't catch these rejections with .catch();
Also, custom validate function is not executing with type: "rawlist", can't evade it this way.

Sample code

await inquirer
	.prompt({
		type: "rawlist",
		name: "list",
		message: "sample list question",
		choices: ["first", "second"],
	})
	.catch((e) => {
		console.log("ERROR");
		console.log(e);
	});

Reproducing the error
WEBM showing error

Full terminal log from sample

? sample list question 
  1) first
  2) second
  Answer: (node:109979) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
>> Please enter a valid index
  assert(_.isNumber(selector))

    at Choices.getChoice (/home/me/Code/e/node_modules/inquirer/lib/objects/choices.js:63:5)
    at RawListPrompt.getCurrentValue (/home/me/Code/e/node_modules/inquirer/lib/prompts/rawlist.js:131:37)
    at /home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    at OperatorSubscriber._this._next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:28:21)
    at OperatorSubscriber.Subscriber.next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:18)
    at Interface.handler (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/observable/fromEvent.js:59:31)
    at Interface.emit (events.js:400:28)
    at Interface._onLine (readline.js:364:10)
    at Interface._line (readline.js:700:8)
    at Interface._ttyWrite (readline.js:1045:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:109979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:109979) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:109979) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(_.isNumber(selector))

    at Choices.getChoice (/home/me/Code/e/node_modules/inquirer/lib/objects/choices.js:63:5)
    at RawListPrompt.getCurrentValue (/home/me/Code/e/node_modules/inquirer/lib/prompts/rawlist.js:131:37)
    at /home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    at OperatorSubscriber._this._next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:28:21)
    at OperatorSubscriber.Subscriber.next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:18)
    at Interface.handler (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/observable/fromEvent.js:59:31)
    at Interface.emit (events.js:400:28)
    at Interface._onLine (readline.js:364:10)
    at Interface._line (readline.js:700:8)
    at Interface._ttyWrite (readline.js:1045:14)
(node:109979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:109979) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(_.isNumber(selector))

    at Choices.getChoice (/home/me/Code/e/node_modules/inquirer/lib/objects/choices.js:63:5)
    at RawListPrompt.getCurrentValue (/home/me/Code/e/node_modules/inquirer/lib/prompts/rawlist.js:131:37)
    at /home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    at OperatorSubscriber._this._next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:28:21)
    at OperatorSubscriber.Subscriber.next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:18)
    at Interface.handler (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/observable/fromEvent.js:59:31)
    at Interface.emit (events.js:400:28)
    at Interface._onLine (readline.js:364:10)
    at Interface._line (readline.js:700:8)
    at Interface._ttyWrite (readline.js:1045:14)
(node:109979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:109979) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(_.isNumber(selector))

    at Choices.getChoice (/home/me/Code/e/node_modules/inquirer/lib/objects/choices.js:63:5)
    at RawListPrompt.getCurrentValue (/home/me/Code/e/node_modules/inquirer/lib/prompts/rawlist.js:131:37)
    at /home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    at OperatorSubscriber._this._next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:28:21)
    at OperatorSubscriber.Subscriber.next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:18)
    at Interface.handler (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/observable/fromEvent.js:59:31)
    at Interface.emit (events.js:400:28)
    at Interface._onLine (readline.js:364:10)
    at Interface._line (readline.js:700:8)
    at Interface._ttyWrite (readline.js:1045:14)
(node:109979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:109979) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(_.isNumber(selector))

    at Choices.getChoice (/home/me/Code/e/node_modules/inquirer/lib/objects/choices.js:63:5)
    at RawListPrompt.getCurrentValue (/home/me/Code/e/node_modules/inquirer/lib/prompts/rawlist.js:131:37)
    at /home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
    at OperatorSubscriber._this._next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:28:21)
    at OperatorSubscriber.Subscriber.next (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:18)
    at Interface.handler (/home/me/Code/e/node_modules/rxjs/dist/cjs/internal/observable/fromEvent.js:59:31)
    at Interface.emit (events.js:400:28)
    at Interface._onLine (readline.js:364:10)
    at Interface._line (readline.js:700:8)
    at Interface._ttyWrite (readline.js:1045:14)
(node:109979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)error message
@SanariSan SanariSan changed the title rawlist throw unhandable rejection rawlist throws unhandable rejection Sep 13, 2021
SBoudrias pushed a commit that referenced this issue Sep 15, 2021
@SBoudrias
Copy link
Owner

Fix is merged, and released to npm. Thanks for the help :)

This was referenced Sep 15, 2021
SBoudrias pushed a commit that referenced this issue Sep 15, 2021
Co-authored-by: SanariSan <[email protected]>
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

2 participants