diff --git a/lib/cli/doctor/index.js b/lib/cli/doctor/index.js index 9be897a1..249e3da7 100644 --- a/lib/cli/doctor/index.js +++ b/lib/cli/doctor/index.js @@ -54,64 +54,64 @@ module.exports.handler = function() { } function check(label, fn) { - return Promise.try(function() { - function Check() { - } + function Check() { + } - Check.prototype.call = function(command, args, options) { - return call(command, args, options).catch(function(err) { - if (err.code === 'ENOENT') { + Check.prototype.call = function(command, args, options) { + return call(command, args, options).catch(function(err) { + if (err.code === 'ENOENT') { + throw new CheckError( + '%s is not installed (`%s` is missing)' + , label + , command + ) + } + + throw err + }) + } + + Check.prototype.extract = function(what, re) { + return function(input) { + return Promise.try(function() { + var match = re.exec(input) + if (!match) { + throw new CheckError(util.format('%s %s cannot be detected', label, what)) + } + return match[1] + }) + } + } + + Check.prototype.version = function(wantedVersion) { + return function(currentVersion) { + return Promise.try(function() { + log.info('Using %s %s', label, currentVersion) + var sanitizedVersion = currentVersion.replace(/~.*/, '') + return semver.satisfies(sanitizedVersion, wantedVersion) + }) + .then(function(satisfied) { + if (!satisfied) { throw new CheckError( - '%s is not installed (`%s` is missing)' + '%s is currently %s but needs to be %s' , label - , command + , currentVersion + , wantedVersion ) } - - throw err }) } + } - Check.prototype.extract = function(what, re) { - return function(input) { - return Promise.try(function() { - var match = re.exec(input) - if (!match) { - throw new CheckError(util.format('%s %s cannot be detected', label, what)) - } - return match[1] - }) - } - } - - Check.prototype.version = function(wantedVersion) { - return function(currentVersion) { - return Promise.try(function() { - log.info('Using %s %s', label, currentVersion) - var sanitizedVersion = currentVersion.replace(/~.*/, '') - return semver.satisfies(sanitizedVersion, wantedVersion) - }) - .then(function(satisfied) { - if (!satisfied) { - throw new CheckError( - '%s is currently %s but needs to be %s' - , label - , currentVersion - , wantedVersion - ) - } - }) - } - } - - return fn(new Check()) - .catch(CheckError, function(err) { - log.error(err.message) - }) - .catch(function(err) { - log.error('Unexpected error checking %s: %s', label, err) - }) - }) + return Promise.try(function() { + return fn(new Check()) + }) + .catch(CheckError, function(err) { + log.error(err.message) + }) + .catch(function(err) { + log.error('Unexpected error checking %s: %s', label, err) + }) } function checkOSArch() {