fix(exec): Handle node string error codes before setting process.exitCode #2031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
os.constants.errno
and returns a number from thereTypeError
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 anENOENT
. The commands fail, butlerna exec
reports success andNaN
exit code: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 andexeca
led me to the observation that a certain code path returns such aresult
whoseresult.code
property can be a node error string likeENOENT
,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
Checklist: