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: Handle error when running init without npm #9169

Merged
merged 1 commit into from Aug 30, 2017

Conversation

GAumala
Copy link
Contributor

@GAumala GAumala commented Aug 28, 2017

Fix init command crashing on machines that don't have npm installed #9102 .

Before:

screenshot from 2017-08-27 22-57-08

After:

screenshot from 2017-08-27 23-59-58

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ X ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)
Modify fetchPeerDependencies() function in npm-util to retun null if the npm process exited with an ENOENT error.
Modify installSyncSaveDev() function in npm-util to log an error message if the npm process exited with an ENOENT error.
Write new tests for fetchPeerDependencies() and installSyncSaveDev() to cover these scenarios.
Modify the sync stub in other installSyncSaveDev() tests to return an object more similar to the child_process object specified in the node.js docs, to avoid undefined field errors.

Is there anything you'd like reviewers to focus on?

I'm not sure if returning null in fetchPeerDependencies() might be the best way of error handling. A consequence of this is that getPeerDependencies() also has to return null in this scenario. Let me know if you think there are better alternatives.
With this change, hasESLintVersionConflict() could potentially throw an error when trying to access the eslint field of a null object. I decided check for null and use an empty object instead, which results in the function returning false in this scenario. I'm not sure what consequences might this change have, and I couldn't figure out a way to test it since it is a private method.

Modify fetchPeerDependencies() function in npm-util to retun null if the
npm process exited with an ENOENT error.
Modify installSyncSaveDev() function in npm-util to log an error message  if the
npm process exited with an ENOENT error.
Write new tests for fetchPeerDependencies() and installSyncSaveDev() to
cover these scenarios.
Modify the sync stub in other installSyncSaveDev() tests to return an object
more similar to the child_process object specified in the node.js docs,
to avoid undefined field errors.
@eslintbot
Copy link

LGTM

@jsf-clabot
Copy link

jsf-clabot commented Aug 28, 2017

CLA assistant check
All committers have signed the CLA.

@mention-bot
Copy link

@GAumala, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mysticatea, @IanVS and @not-an-aardvark to be potential reviewers.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface labels Aug 29, 2017
Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for contributing!

@not-an-aardvark not-an-aardvark merged commit af4ad60 into eslint:master Aug 30, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 27, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants