Improve output when failing to get a version from "a place" (#334)

This commit is contained in:
Paulo F. Oliveira
2025-05-28 23:42:50 +01:00
committed by GitHub
parent a770081419
commit 891e46b77a
2 changed files with 90 additions and 64 deletions
+45 -32
View File
@@ -9268,20 +9268,30 @@ async function maybeInstallRebar3(rebar3Spec) {
} }
async function getOTPVersion(otpSpec0, osVersion) { async function getOTPVersion(otpSpec0, osVersion) {
const otpVersions = await getOTPVersions(osVersion) const [otpVersions, originListing, hexMirrors] = await getOTPVersions(
osVersion,
)
let spec = otpSpec0.replace(/^OTP-/, '') let spec = otpSpec0.replace(/^OTP-/, '')
const versions = otpVersions const versions = otpVersions
const otpVersion = getVersionFromSpec(spec, versions) const otpVersion = getVersionFromSpec(spec, versions)
if (otpVersion === null) { if (otpVersion === null) {
throw new Error( throw new Error(
`Requested Erlang/OTP version (${otpSpec0}) not found in version list ` + requestedVersionFor('Erlang/OTP', otpSpec0, originListing, hexMirrors),
"(should you be using option 'version-type': 'strict'?)",
) )
} }
return otpVersion // from the reference, for download return otpVersion // from the reference, for download
} }
function requestedVersionFor(tool, version, originListing, mirrors) {
return (
`Requested ${tool} version (${version}) not found in version list, ` +
`at ${originListing}${mirrors ? `, with mirrors ${mirrors}` : ''}; ` +
"should you be using option 'version-type': 'strict'?"
)
}
async function getElixirVersion(exSpec0, otpVersion0) { async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2] const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1] let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
@@ -9292,15 +9302,15 @@ async function getElixirVersion(exSpec0, otpVersion0) {
otpVersionMajor = userSuppliedOtp otpVersionMajor = userSuppliedOtp
} }
const [otpVersionsForElixirMap, elixirVersions] = await getElixirVersions() const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
await getElixirVersions()
const spec = exSpec0.replace(/-otp-.*$/, '') const spec = exSpec0.replace(/-otp-.*$/, '')
const versions = elixirVersions const versions = elixirVersions
const elixirVersionFromSpec = getVersionFromSpec(spec, versions) const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
if (elixirVersionFromSpec === null) { if (elixirVersionFromSpec === null) {
throw new Error( throw new Error(
`Requested Elixir version (${exSpec0}) not found in version list ` + requestedVersionFor('Elixir', exSpec0, originListing, hexMirrors),
"(should you be using option 'version-type': 'strict'?)",
) )
} }
@@ -9331,30 +9341,26 @@ async function getElixirVersion(exSpec0, otpVersion0) {
} }
async function getGleamVersion(gleamSpec0) { async function getGleamVersion(gleamSpec0) {
const gleamVersions = await getGleamVersions() const [gleamVersions, originListing] = await getGleamVersions()
const spec = gleamSpec0 const spec = gleamSpec0
const versions = gleamVersions const versions = gleamVersions
const gleamVersion = getVersionFromSpec(spec, versions) const gleamVersion = getVersionFromSpec(spec, versions)
if (gleamVersion === null) { if (gleamVersion === null) {
throw new Error( throw new Error(requestedVersionFor('Gleam', gleamSpec0, originListing))
`Requested Gleam version (${gleamSpec0}) not found in version list ` +
"(should you be using option 'version-type': 'strict'?)",
)
} }
return maybePrependWithV(gleamVersion) return maybePrependWithV(gleamVersion)
} }
async function getRebar3Version(r3Spec) { async function getRebar3Version(r3Spec) {
const rebar3Versions = await getRebar3Versions() const [rebar3Versions, originListing] = await getRebar3Versions()
const spec = r3Spec const spec = r3Spec
const versions = rebar3Versions const versions = rebar3Versions
const rebar3Version = getVersionFromSpec(spec, versions) const rebar3Version = getVersionFromSpec(spec, versions)
if (rebar3Version === null) { if (rebar3Version === null) {
throw new Error( throw new Error(requestedVersionFor('rebar3', r3Spec, originListing))
`Requested rebar3 version (${r3Spec}) not found in version list ` +
"(should you be using option 'version-type': 'strict'?)",
)
} }
return rebar3Version return rebar3Version
@@ -9363,10 +9369,12 @@ async function getRebar3Version(r3Spec) {
async function getOTPVersions(osVersion) { async function getOTPVersions(osVersion) {
let otpVersionsListings let otpVersionsListings
let originListing let originListing
let hexMirrors = null
if (process.platform === 'linux') { if (process.platform === 'linux') {
originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt` originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt`
hexMirrors = hexMirrorsInput()
otpVersionsListings = await doWithMirrors({ otpVersionsListings = await doWithMirrors({
hexMirrors: hexMirrorsInput(), hexMirrors,
actionTitle: `fetch ${originListing}`, actionTitle: `fetch ${originListing}`,
action: async (hexMirror) => { action: async (hexMirror) => {
return get(`${hexMirror}${originListing}`, []) return get(`${hexMirror}${originListing}`, [])
@@ -9378,7 +9386,10 @@ async function getOTPVersions(osVersion) {
otpVersionsListings = await get(originListing, [1, 2, 3]) otpVersionsListings = await get(originListing, [1, 2, 3])
} }
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings) debugLog(
`OTP versions listings from ${originListing}, mirrors ${hexMirrors}`,
otpVersionsListings,
)
const otpVersions = {} const otpVersions = {}
if (process.platform === 'linux') { if (process.platform === 'linux') {
@@ -9412,15 +9423,19 @@ async function getOTPVersions(osVersion) {
}) })
} }
debugLog(`OTP versions from ${originListing}`, JSON.stringify(otpVersions)) debugLog(
`OTP versions from ${originListing}, mirrors ${hexMirrors}`,
JSON.stringify(otpVersions),
)
return otpVersions return [otpVersions, originListing, hexMirrors]
} }
async function getElixirVersions() { async function getElixirVersions() {
const originListing = '/builds/elixir/builds.txt' const originListing = '/builds/elixir/builds.txt'
const hexMirrors = hexMirrorsInput()
const elixirVersionsListings = await doWithMirrors({ const elixirVersionsListings = await doWithMirrors({
hexMirrors: hexMirrorsInput(), hexMirrors,
actionTitle: `fetch ${originListing}`, actionTitle: `fetch ${originListing}`,
action: async (hexMirror) => { action: async (hexMirror) => {
return get(`${hexMirror}${originListing}`, []) return get(`${hexMirror}${originListing}`, [])
@@ -9446,14 +9461,13 @@ async function getElixirVersions() {
elixirVersions[elixirVersion] = elixirVersion elixirVersions[elixirVersion] = elixirVersion
}) })
return [otpVersionsForElixirMap, elixirVersions] return [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors]
} }
async function getGleamVersions() { async function getGleamVersions() {
const resultJSONs = await get( const originListing =
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100', 'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100'
[1, 2, 3], const resultJSONs = await get(originListing, [1, 2, 3])
)
const gleamVersionsListing = {} const gleamVersionsListing = {}
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
resultJSON resultJSON
@@ -9465,14 +9479,13 @@ async function getGleamVersions() {
}) })
}) })
return gleamVersionsListing return [gleamVersionsListing, originListing]
} }
async function getRebar3Versions() { async function getRebar3Versions() {
const resultJSONs = await get( const originListing =
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100', 'https://api.github.com/repos/erlang/rebar3/releases?per_page=100'
[1, 2, 3], const resultJSONs = await get(originListing, [1, 2, 3])
)
const rebar3VersionsListing = {} const rebar3VersionsListing = {}
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
resultJSON resultJSON
@@ -9482,7 +9495,7 @@ async function getRebar3Versions() {
}) })
}) })
return rebar3VersionsListing return [rebar3VersionsListing, originListing]
} }
function isStrictVersion() { function isStrictVersion() {
+45 -32
View File
@@ -168,20 +168,30 @@ async function maybeInstallRebar3(rebar3Spec) {
} }
async function getOTPVersion(otpSpec0, osVersion) { async function getOTPVersion(otpSpec0, osVersion) {
const otpVersions = await getOTPVersions(osVersion) const [otpVersions, originListing, hexMirrors] = await getOTPVersions(
osVersion,
)
let spec = otpSpec0.replace(/^OTP-/, '') let spec = otpSpec0.replace(/^OTP-/, '')
const versions = otpVersions const versions = otpVersions
const otpVersion = getVersionFromSpec(spec, versions) const otpVersion = getVersionFromSpec(spec, versions)
if (otpVersion === null) { if (otpVersion === null) {
throw new Error( throw new Error(
`Requested Erlang/OTP version (${otpSpec0}) not found in version list ` + requestedVersionFor('Erlang/OTP', otpSpec0, originListing, hexMirrors),
"(should you be using option 'version-type': 'strict'?)",
) )
} }
return otpVersion // from the reference, for download return otpVersion // from the reference, for download
} }
function requestedVersionFor(tool, version, originListing, mirrors) {
return (
`Requested ${tool} version (${version}) not found in version list, ` +
`at ${originListing}${mirrors ? `, with mirrors ${mirrors}` : ''}; ` +
"should you be using option 'version-type': 'strict'?"
)
}
async function getElixirVersion(exSpec0, otpVersion0) { async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2] const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1] let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
@@ -192,15 +202,15 @@ async function getElixirVersion(exSpec0, otpVersion0) {
otpVersionMajor = userSuppliedOtp otpVersionMajor = userSuppliedOtp
} }
const [otpVersionsForElixirMap, elixirVersions] = await getElixirVersions() const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
await getElixirVersions()
const spec = exSpec0.replace(/-otp-.*$/, '') const spec = exSpec0.replace(/-otp-.*$/, '')
const versions = elixirVersions const versions = elixirVersions
const elixirVersionFromSpec = getVersionFromSpec(spec, versions) const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
if (elixirVersionFromSpec === null) { if (elixirVersionFromSpec === null) {
throw new Error( throw new Error(
`Requested Elixir version (${exSpec0}) not found in version list ` + requestedVersionFor('Elixir', exSpec0, originListing, hexMirrors),
"(should you be using option 'version-type': 'strict'?)",
) )
} }
@@ -231,30 +241,26 @@ async function getElixirVersion(exSpec0, otpVersion0) {
} }
async function getGleamVersion(gleamSpec0) { async function getGleamVersion(gleamSpec0) {
const gleamVersions = await getGleamVersions() const [gleamVersions, originListing] = await getGleamVersions()
const spec = gleamSpec0 const spec = gleamSpec0
const versions = gleamVersions const versions = gleamVersions
const gleamVersion = getVersionFromSpec(spec, versions) const gleamVersion = getVersionFromSpec(spec, versions)
if (gleamVersion === null) { if (gleamVersion === null) {
throw new Error( throw new Error(requestedVersionFor('Gleam', gleamSpec0, originListing))
`Requested Gleam version (${gleamSpec0}) not found in version list ` +
"(should you be using option 'version-type': 'strict'?)",
)
} }
return maybePrependWithV(gleamVersion) return maybePrependWithV(gleamVersion)
} }
async function getRebar3Version(r3Spec) { async function getRebar3Version(r3Spec) {
const rebar3Versions = await getRebar3Versions() const [rebar3Versions, originListing] = await getRebar3Versions()
const spec = r3Spec const spec = r3Spec
const versions = rebar3Versions const versions = rebar3Versions
const rebar3Version = getVersionFromSpec(spec, versions) const rebar3Version = getVersionFromSpec(spec, versions)
if (rebar3Version === null) { if (rebar3Version === null) {
throw new Error( throw new Error(requestedVersionFor('rebar3', r3Spec, originListing))
`Requested rebar3 version (${r3Spec}) not found in version list ` +
"(should you be using option 'version-type': 'strict'?)",
)
} }
return rebar3Version return rebar3Version
@@ -263,10 +269,12 @@ async function getRebar3Version(r3Spec) {
async function getOTPVersions(osVersion) { async function getOTPVersions(osVersion) {
let otpVersionsListings let otpVersionsListings
let originListing let originListing
let hexMirrors = null
if (process.platform === 'linux') { if (process.platform === 'linux') {
originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt` originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt`
hexMirrors = hexMirrorsInput()
otpVersionsListings = await doWithMirrors({ otpVersionsListings = await doWithMirrors({
hexMirrors: hexMirrorsInput(), hexMirrors,
actionTitle: `fetch ${originListing}`, actionTitle: `fetch ${originListing}`,
action: async (hexMirror) => { action: async (hexMirror) => {
return get(`${hexMirror}${originListing}`, []) return get(`${hexMirror}${originListing}`, [])
@@ -278,7 +286,10 @@ async function getOTPVersions(osVersion) {
otpVersionsListings = await get(originListing, [1, 2, 3]) otpVersionsListings = await get(originListing, [1, 2, 3])
} }
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings) debugLog(
`OTP versions listings from ${originListing}, mirrors ${hexMirrors}`,
otpVersionsListings,
)
const otpVersions = {} const otpVersions = {}
if (process.platform === 'linux') { if (process.platform === 'linux') {
@@ -312,15 +323,19 @@ async function getOTPVersions(osVersion) {
}) })
} }
debugLog(`OTP versions from ${originListing}`, JSON.stringify(otpVersions)) debugLog(
`OTP versions from ${originListing}, mirrors ${hexMirrors}`,
JSON.stringify(otpVersions),
)
return otpVersions return [otpVersions, originListing, hexMirrors]
} }
async function getElixirVersions() { async function getElixirVersions() {
const originListing = '/builds/elixir/builds.txt' const originListing = '/builds/elixir/builds.txt'
const hexMirrors = hexMirrorsInput()
const elixirVersionsListings = await doWithMirrors({ const elixirVersionsListings = await doWithMirrors({
hexMirrors: hexMirrorsInput(), hexMirrors,
actionTitle: `fetch ${originListing}`, actionTitle: `fetch ${originListing}`,
action: async (hexMirror) => { action: async (hexMirror) => {
return get(`${hexMirror}${originListing}`, []) return get(`${hexMirror}${originListing}`, [])
@@ -346,14 +361,13 @@ async function getElixirVersions() {
elixirVersions[elixirVersion] = elixirVersion elixirVersions[elixirVersion] = elixirVersion
}) })
return [otpVersionsForElixirMap, elixirVersions] return [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors]
} }
async function getGleamVersions() { async function getGleamVersions() {
const resultJSONs = await get( const originListing =
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100', 'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100'
[1, 2, 3], const resultJSONs = await get(originListing, [1, 2, 3])
)
const gleamVersionsListing = {} const gleamVersionsListing = {}
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
resultJSON resultJSON
@@ -365,14 +379,13 @@ async function getGleamVersions() {
}) })
}) })
return gleamVersionsListing return [gleamVersionsListing, originListing]
} }
async function getRebar3Versions() { async function getRebar3Versions() {
const resultJSONs = await get( const originListing =
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100', 'https://api.github.com/repos/erlang/rebar3/releases?per_page=100'
[1, 2, 3], const resultJSONs = await get(originListing, [1, 2, 3])
)
const rebar3VersionsListing = {} const rebar3VersionsListing = {}
resultJSONs.forEach((resultJSON) => { resultJSONs.forEach((resultJSON) => {
resultJSON resultJSON
@@ -382,7 +395,7 @@ async function getRebar3Versions() {
}) })
}) })
return rebar3VersionsListing return [rebar3VersionsListing, originListing]
} }
function isStrictVersion() { function isStrictVersion() {