matt-ball / postman-local

A client to facilitate local development of scripts for Postman.
Apache License 2.0
70 stars 6 forks source link

Unhandled Promise rejection on setup when no environments exist. #35

Closed kevinswiber closed 3 years ago

kevinswiber commented 4 years ago

I'm getting this error on postman setup when choosing to include environments when none actually exist in the workspace.

✔ Would you like to include Environment(s)? (y/N) · true
(node:31358) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
    at createChoices (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/lib/create-choices.js:2:14)
    at continueSetup (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/setup.js:70:32)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:31358) 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:31358) [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.

The error appears to be coming from here: https://github.com/matt-ball/postman-cli/blob/0fb32ef68060ac42a0bc77f67ece2dd947c51f94/src/setup.js#L70

When no environments exist, there actually is no data.workspace.environments field in the API response, so it's sending undefined to createChoices.