Skip to content

Commit

Permalink
Improve error message when a version is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 4, 2020
1 parent 77cddd7 commit 7d189e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ async function getRubyEngineAndVersion(rubyVersion) {
const stableVersions = response.data
const engineVersions = stableVersions[engine]
if (!engineVersions) {
throw new Error(`Unknown engine ${engine} (${rubyVersion})`)
throw new Error(`Unknown engine ${engine} (input: ${rubyVersion})`)
}

if (!engineVersions.includes(version)) {
engineVersions.reverse() // inplace!
let found = engineVersions.find(v => v.startsWith(version))
const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => v.startsWith(version))
if (found) {
version = found
} else {
throw new Error(`Unknown version ${version} (${rubyVersion})`)
throw new Error(`Unknown version ${version} for ${engine}
input: ${rubyVersion}
available versions for ${engine}: ${engineVersions.join(', ')}
File an issue at https://github.com/eregon/ruby-install-builder/issues if would like support for a new version`)
}
}

Expand Down

0 comments on commit 7d189e2

Please sign in to comment.