Skip to content

Commit

Permalink
Handle Windows command not found error being different
Browse files Browse the repository at this point in the history
Using cross-spawn on Windows will return returnCode=1 and use stderr
message when command is not found. However it is expected that an Error is
returned from spawn in that case and error.code is ENOENT. This commit
handles Windows explicitly by checking if it is Windows, for the
returnCode, and also if the error message is appropriate.

Example Windows command not found error message:
	'command' is not recognized as an internal or external command,
	operable program or batch file.

/cc #397
  • Loading branch information
Glavin001 committed Jun 14, 2015
1 parent c93b1f8 commit 57ffe75
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/beautifiers/beautifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,18 @@ module.exports = class Beautifier
env: env
}
cmd = @spawn(exe, args, options)
.then(({returnCode, stdout, stderr}) ->
.then(({returnCode, stdout, stderr}) =>
@verbose('spawn result', returnCode, stdout, stderr)
# If return code is not 0 then error occured
if not ignoreReturnCode and returnCode isnt 0
reject(stderr)
err = new Error(stderr)
windowsProgramNotFoundMsg = 'is not recognized as an \
internal or external command'#, operable program or batch file.'
@verbose(stderr, windowsProgramNotFoundMsg)
if @isWindows and returnCode is 1 and \
stderr.indexOf(windowsProgramNotFoundMsg) isnt -1
err = @commandNotFoundError(exeName, help)
reject(err)
else
resolve(stdout)
)
Expand Down

0 comments on commit 57ffe75

Please sign in to comment.