From 57ffe7543b6599c48fb878a6ffc89c0ca19af833 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 14 Jun 2015 11:03:12 -0300 Subject: [PATCH] Handle Windows command not found error being different 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 --- src/beautifiers/beautifier.coffee | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index d43a6c0b9..2dfaa026b 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -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) )