1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Make sure that check actually catches and handles errors, even if synchronous.

This commit is contained in:
Simo Kinnunen 2017-04-29 12:55:15 +09:00
parent 6bf300e29d
commit 2b836f6382

View file

@ -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() {