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 TypeError in case no files were found #295

Merged
merged 1 commit into from Jan 16, 2019

Conversation

skovhus
Copy link
Contributor

@skovhus skovhus commented Dec 8, 2018

In case no files are found then jscodeshift crashes with a TypeError as pendingWorkers are undefined, so Promise.all(pendingWorkers) will fail.

Output before this PR:

No files selected, nothing to do. 
(node:56389) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
    at Function.all (<anonymous>)
    at getAllFiles.then.then.pendingWorkers (/node_modules/jscodeshift/src/Runner.js:292:17)
(node:56389) 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(). (rejection id: 3)
(node:56389) [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.

After this PR the output looks as expected:

No files selected, nothing to do. 
All done. 
Results: 
0 errors
0 unmodified
0 skipped
0 ok

Alternatives

I was considering if we should simply do a process.exit, but that wouldn't work if people use jscodeshift directly as a node dependency. I think the proposed solution here is the simplest for now.

Fixes "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined"
@skovhus
Copy link
Contributor Author

skovhus commented Jan 4, 2019

@fkling anything I can do to land this?

@fkling fkling merged commit 16fcf0a into facebook:master Jan 16, 2019
@fkling
Copy link
Contributor

fkling commented Jan 16, 2019

Sorry for the wait!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants