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: Add better logging for command not found errors #421

Merged
merged 1 commit into from
Nov 15, 2019

Conversation

wwilsman
Copy link
Contributor

@wwilsman wwilsman commented Nov 15, 2019

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's error handler being interpreted incorrectly by Winston 3.x. Winston attempts to find a msg property on the passed object, which is where undefined 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 dependency which 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.

🐛 Fix error logging from the child process promise
src/commands/exec.ts Show resolved Hide resolved
test/acceptance/exec.test.js Show resolved Hide resolved
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

🏁 Woop!

@wwilsman wwilsman merged commit 689a869 into master Nov 15, 2019
@wwilsman wwilsman deleted the ww/command-not-found-error branch November 15, 2019 19:41
djones pushed a commit that referenced this pull request Nov 15, 2019
## [0.20.1](v0.20.0...v0.20.1) (2019-11-15)

### Bug Fixes

* Add better logging for command not found errors ([#421](#421)) ([689a869](689a869))
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.

Gracefully exit with a nice error if we can't find the passed command
2 participants