fix: Add better logging for command not found errors #421
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.
Purpose
We started noticing
[percy] undefined
in the logs whenever the command being executed was not found in the $PATH. This was due to the error object being passed through from the child'serror
handler being interpreted incorrectly by Winston 3.x. Winston attempts to find amsg
property on the passed object, which is whereundefined
was coming from. Winston does have logic for handling Error instances, but for some reason the error provided by cross-spawn did not get handled like a normal Error.Fixes #297
Approach
Call
.toString()
on the error to log the error message rather than the error object.The error this produced was
spawn foobar ENOENT
which might not be obvious to some that it means the command was not found. So I utilized a transitive dependencywhich
to perform a cross-platform check for the provided command so we can log a much friendlier error.In addition, I added a non-zero exit code to the missing command logic and tested that as well.