Improve error message

This commit is contained in:
Benoit Daloze
2020-01-19 22:55:15 +01:00
parent 7da380d64e
commit 0f26fedc26
2 changed files with 12 additions and 16 deletions
Generated Vendored
+6 -8
View File
@@ -1393,10 +1393,9 @@ async function run() {
installer = __webpack_require__(442)
}
const input = core.getInput('ruby-version')
const [engine, version] = parseRubyEngineAndVersion(input)
const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
const engineVersions = await installer.getAvailableVersions(engine)
const ruby = validateRubyEngineAndVersion(engineVersions, input, engine, version)
const ruby = validateRubyEngineAndVersion(platform, engineVersions, engine, version)
const rubyPrefix = await installer.install(platform, ruby)
core.setOutput('ruby-prefix', rubyPrefix)
@@ -1425,9 +1424,9 @@ function parseRubyEngineAndVersion(rubyVersion) {
return [engine, version]
}
function validateRubyEngineAndVersion(engineVersions, input, engine, version) {
function validateRubyEngineAndVersion(platform, engineVersions, engine, version) {
if (!engineVersions) {
throw new Error(`Unknown engine ${engine} (input: ${input})`)
throw new Error(`Unknown engine ${engine} on ${platform}`)
}
if (!engineVersions.includes(version)) {
@@ -1436,9 +1435,8 @@ function validateRubyEngineAndVersion(engineVersions, input, engine, version) {
if (found) {
version = found
} else {
throw new Error(`Unknown version ${version} for ${engine}
input: ${input}
available versions for ${engine}: ${engineVersions.join(', ')}
throw new Error(`Unknown version ${version} for ${engine} on ${platform}
available versions for ${engine} on ${platform}: ${engineVersions.join(', ')}
File an issue at https://github.com/eregon/use-ruby-action/issues if would like support for a new version`)
}
}
+6 -8
View File
@@ -12,10 +12,9 @@ async function run() {
installer = require('./ruby-install-builder')
}
const input = core.getInput('ruby-version')
const [engine, version] = parseRubyEngineAndVersion(input)
const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
const engineVersions = await installer.getAvailableVersions(engine)
const ruby = validateRubyEngineAndVersion(engineVersions, input, engine, version)
const ruby = validateRubyEngineAndVersion(platform, engineVersions, engine, version)
const rubyPrefix = await installer.install(platform, ruby)
core.setOutput('ruby-prefix', rubyPrefix)
@@ -44,9 +43,9 @@ function parseRubyEngineAndVersion(rubyVersion) {
return [engine, version]
}
function validateRubyEngineAndVersion(engineVersions, input, engine, version) {
function validateRubyEngineAndVersion(platform, engineVersions, engine, version) {
if (!engineVersions) {
throw new Error(`Unknown engine ${engine} (input: ${input})`)
throw new Error(`Unknown engine ${engine} on ${platform}`)
}
if (!engineVersions.includes(version)) {
@@ -55,9 +54,8 @@ function validateRubyEngineAndVersion(engineVersions, input, engine, version) {
if (found) {
version = found
} else {
throw new Error(`Unknown version ${version} for ${engine}
input: ${input}
available versions for ${engine}: ${engineVersions.join(', ')}
throw new Error(`Unknown version ${version} for ${engine} on ${platform}
available versions for ${engine} on ${platform}: ${engineVersions.join(', ')}
File an issue at https://github.com/eregon/use-ruby-action/issues if would like support for a new version`)
}
}