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

fix: gracefully error on missing message #1575

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mshima
Copy link
Contributor

@mshima mshima commented Oct 11, 2024

No description provided.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@4831899). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1575   +/-   ##
=======================================
  Coverage        ?   98.03%           
=======================================
  Files           ?       39           
  Lines           ?     2391           
  Branches        ?      646           
=======================================
  Hits            ?     2344           
  Misses          ?       40           
  Partials        ?        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +78 to +80
if (nextView === undefined) {
throw new Error('Question is missing a message');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessarily true here right; many reasons why a view function might return nothing (could just fail or have an internal bug that is not due to message.)

Do you have an example error where this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case is to create a dummy non interactive prompt to be used in yeoman-test.
Error is:

TypeError: (intermediate value)(intermediate value)(intermediate value) is not iterable
 ❯ node_modules/@inquirer/core/dist/esm/lib/create-prompt.js:57:54
 ❯ Object.store.handleChange node_modules/@inquirer/core/dist/esm/lib/hook-engine.js:23:17
 ❯ cycle node_modules/@inquirer/core/dist/esm/lib/hook-engine.js:25:19
 ❯ node_modules/@inquirer/core/dist/esm/lib/create-prompt.js:52:13
 ❯ node_modules/@inquirer/core/dist/esm/lib/hook-engine.js:27:16
 ❯ withHooks node_modules/@inquirer/core/dist/esm/lib/hook-engine.js:19:24
 ❯ prompt node_modules/@inquirer/core/dist/esm/lib/create-prompt.js:45:16
 ❯ PromptsRunner.fetchAnswer node_modules/inquirer/dist/esm/ui/prompt.js:227:16

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the error should be intercepted elsewhere but it's quite complicated to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executing await input({}) shows:

? undefined

Maybe a default message instead then?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm not completely following.

  1. If you create a dummy prompt, you could still return a string from the render function and that wouldn't error out no?
  2. I don't understand how input ends up called with no message - can you clarify how it gets there?

I'm okay validating and throwing an error inside @inquirer/core, but we should review the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If you create a dummy prompt, you could still return a string from the render function and that wouldn't error out no?

The dummy prompt is returning the config.message which was undefined.
https://github.com/yeoman/yeoman-api/blob/e43ca2ca7e842c53a06cce3d990d2050aa2d1ccb/workspaces/adapter/src/testing/test-adapter.ts#L73

I had to debug to discover the error while migrating to new inquirer in tests.
message is mandatory in runtime, it was missing in some tests.

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

Successfully merging this pull request may close these issues.

2 participants