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(exec): Handle node string error codes before setting process.exitCode #2031

Merged
merged 1 commit into from Apr 16, 2019
Merged

fix(exec): Handle node string error codes before setting process.exitCode #2031

merged 1 commit into from Apr 16, 2019

Conversation

KonstantinSimeonov
Copy link
Contributor

@KonstantinSimeonov KonstantinSimeonov commented Apr 11, 2019

Thanks for the awesome project!

Handle node string error codes before setting process.exitCode in implementation of lerna exec command.

Description

Added a switch statement based on the result exit code type that does the following:

  • in case of a number exit code simply returns it
  • in case of a string error code looks it up in os.constants.errno and returns a number from there
  • in case of another type throws a TypeError

Also added a unit test, but since it can only fail under windows, and lerna does not seem to run tests under windows, I'm not sure how useful that test will be.

Motivation and Context

Yesterday I ran into a problem with lerna exec under windows 10 (this does not seem to happen under linux). I do the following:

lerna exec --concurrency=1 --no-bail -- custom-command

Where custom-command could potentially fail with an ENOENT. The commands fail, but lerna exec reports success and NaN exit code:
GH SS

The exit code gets swallowed and some tools, like git hooks, successfully pass, when that shouldn't be the case.

Some investigation into your child-process module and execa led me to the observation that a certain code path returns such a result whose result.code property can be a node error string like ENOENT, EEXIST and so on.

I'm not a 100% sure that my way is the best way to address this, moving this logic to child-process might be better.

How Has This Been Tested?

Added a unit test which fails under windows without my changes and passes when they're applied. Also gave it a spin on my linux machine.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@evocateur evocateur merged commit c599c64 into lerna:master Apr 16, 2019
evocateur added a commit that referenced this pull request Apr 17, 2019
@evocateur
Copy link
Member

I ended up moving the logic into @lerna/child-process (covering lerna run and the single-package exec failure cases), but I appreciate the original effort!

@KonstantinSimeonov
Copy link
Contributor Author

That's what I think is more appropriate as well, to potentially handle the case in all places, but I didn't feel like going through all the cases to see whether I would break something with the change :P

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.

None yet

2 participants