-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
if (nextView === undefined) { | ||
throw new Error('Question is missing a message'); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
- If you create a dummy prompt, you could still return a string from the render function and that wouldn't error out no?
- I don't understand how
input
ends up called with nomessage
- 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
No description provided.