Skip to content

Commit 891e46b

Browse files
Improve output when failing to get a version from "a place" (#334)
1 parent a770081 commit 891e46b

File tree

2 files changed

+90
-64
lines changed

2 files changed

+90
-64
lines changed

dist/index.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9268,20 +9268,30 @@ async function maybeInstallRebar3(rebar3Spec) {
92689268
}
92699269

92709270
async function getOTPVersion(otpSpec0, osVersion) {
9271-
const otpVersions = await getOTPVersions(osVersion)
9271+
const [otpVersions, originListing, hexMirrors] = await getOTPVersions(
9272+
osVersion,
9273+
)
92729274
let spec = otpSpec0.replace(/^OTP-/, '')
92739275
const versions = otpVersions
92749276
const otpVersion = getVersionFromSpec(spec, versions)
9277+
92759278
if (otpVersion === null) {
92769279
throw new Error(
9277-
`Requested Erlang/OTP version (${otpSpec0}) not found in version list ` +
9278-
"(should you be using option 'version-type': 'strict'?)",
9280+
requestedVersionFor('Erlang/OTP', otpSpec0, originListing, hexMirrors),
92799281
)
92809282
}
92819283

92829284
return otpVersion // from the reference, for download
92839285
}
92849286

9287+
function requestedVersionFor(tool, version, originListing, mirrors) {
9288+
return (
9289+
`Requested ${tool} version (${version}) not found in version list, ` +
9290+
`at ${originListing}${mirrors ? `, with mirrors ${mirrors}` : ''}; ` +
9291+
"should you be using option 'version-type': 'strict'?"
9292+
)
9293+
}
9294+
92859295
async function getElixirVersion(exSpec0, otpVersion0) {
92869296
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
92879297
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
@@ -9292,15 +9302,15 @@ async function getElixirVersion(exSpec0, otpVersion0) {
92929302
otpVersionMajor = userSuppliedOtp
92939303
}
92949304

9295-
const [otpVersionsForElixirMap, elixirVersions] = await getElixirVersions()
9305+
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
9306+
await getElixirVersions()
92969307
const spec = exSpec0.replace(/-otp-.*$/, '')
92979308
const versions = elixirVersions
92989309
const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
92999310

93009311
if (elixirVersionFromSpec === null) {
93019312
throw new Error(
9302-
`Requested Elixir version (${exSpec0}) not found in version list ` +
9303-
"(should you be using option 'version-type': 'strict'?)",
9313+
requestedVersionFor('Elixir', exSpec0, originListing, hexMirrors),
93049314
)
93059315
}
93069316

@@ -9331,30 +9341,26 @@ async function getElixirVersion(exSpec0, otpVersion0) {
93319341
}
93329342

93339343
async function getGleamVersion(gleamSpec0) {
9334-
const gleamVersions = await getGleamVersions()
9344+
const [gleamVersions, originListing] = await getGleamVersions()
93359345
const spec = gleamSpec0
93369346
const versions = gleamVersions
93379347
const gleamVersion = getVersionFromSpec(spec, versions)
9348+
93389349
if (gleamVersion === null) {
9339-
throw new Error(
9340-
`Requested Gleam version (${gleamSpec0}) not found in version list ` +
9341-
"(should you be using option 'version-type': 'strict'?)",
9342-
)
9350+
throw new Error(requestedVersionFor('Gleam', gleamSpec0, originListing))
93439351
}
93449352

93459353
return maybePrependWithV(gleamVersion)
93469354
}
93479355

93489356
async function getRebar3Version(r3Spec) {
9349-
const rebar3Versions = await getRebar3Versions()
9357+
const [rebar3Versions, originListing] = await getRebar3Versions()
93509358
const spec = r3Spec
93519359
const versions = rebar3Versions
93529360
const rebar3Version = getVersionFromSpec(spec, versions)
9361+
93539362
if (rebar3Version === null) {
9354-
throw new Error(
9355-
`Requested rebar3 version (${r3Spec}) not found in version list ` +
9356-
"(should you be using option 'version-type': 'strict'?)",
9357-
)
9363+
throw new Error(requestedVersionFor('rebar3', r3Spec, originListing))
93589364
}
93599365

93609366
return rebar3Version
@@ -9363,10 +9369,12 @@ async function getRebar3Version(r3Spec) {
93639369
async function getOTPVersions(osVersion) {
93649370
let otpVersionsListings
93659371
let originListing
9372+
let hexMirrors = null
93669373
if (process.platform === 'linux') {
93679374
originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt`
9375+
hexMirrors = hexMirrorsInput()
93689376
otpVersionsListings = await doWithMirrors({
9369-
hexMirrors: hexMirrorsInput(),
9377+
hexMirrors,
93709378
actionTitle: `fetch ${originListing}`,
93719379
action: async (hexMirror) => {
93729380
return get(`${hexMirror}${originListing}`, [])
@@ -9378,7 +9386,10 @@ async function getOTPVersions(osVersion) {
93789386
otpVersionsListings = await get(originListing, [1, 2, 3])
93799387
}
93809388

9381-
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings)
9389+
debugLog(
9390+
`OTP versions listings from ${originListing}, mirrors ${hexMirrors}`,
9391+
otpVersionsListings,
9392+
)
93829393

93839394
const otpVersions = {}
93849395
if (process.platform === 'linux') {
@@ -9412,15 +9423,19 @@ async function getOTPVersions(osVersion) {
94129423
})
94139424
}
94149425

9415-
debugLog(`OTP versions from ${originListing}`, JSON.stringify(otpVersions))
9426+
debugLog(
9427+
`OTP versions from ${originListing}, mirrors ${hexMirrors}`,
9428+
JSON.stringify(otpVersions),
9429+
)
94169430

9417-
return otpVersions
9431+
return [otpVersions, originListing, hexMirrors]
94189432
}
94199433

94209434
async function getElixirVersions() {
94219435
const originListing = '/builds/elixir/builds.txt'
9436+
const hexMirrors = hexMirrorsInput()
94229437
const elixirVersionsListings = await doWithMirrors({
9423-
hexMirrors: hexMirrorsInput(),
9438+
hexMirrors,
94249439
actionTitle: `fetch ${originListing}`,
94259440
action: async (hexMirror) => {
94269441
return get(`${hexMirror}${originListing}`, [])
@@ -9446,14 +9461,13 @@ async function getElixirVersions() {
94469461
elixirVersions[elixirVersion] = elixirVersion
94479462
})
94489463

9449-
return [otpVersionsForElixirMap, elixirVersions]
9464+
return [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors]
94509465
}
94519466

94529467
async function getGleamVersions() {
9453-
const resultJSONs = await get(
9454-
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100',
9455-
[1, 2, 3],
9456-
)
9468+
const originListing =
9469+
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100'
9470+
const resultJSONs = await get(originListing, [1, 2, 3])
94579471
const gleamVersionsListing = {}
94589472
resultJSONs.forEach((resultJSON) => {
94599473
resultJSON
@@ -9465,14 +9479,13 @@ async function getGleamVersions() {
94659479
})
94669480
})
94679481

9468-
return gleamVersionsListing
9482+
return [gleamVersionsListing, originListing]
94699483
}
94709484

94719485
async function getRebar3Versions() {
9472-
const resultJSONs = await get(
9473-
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100',
9474-
[1, 2, 3],
9475-
)
9486+
const originListing =
9487+
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100'
9488+
const resultJSONs = await get(originListing, [1, 2, 3])
94769489
const rebar3VersionsListing = {}
94779490
resultJSONs.forEach((resultJSON) => {
94789491
resultJSON
@@ -9482,7 +9495,7 @@ async function getRebar3Versions() {
94829495
})
94839496
})
94849497

9485-
return rebar3VersionsListing
9498+
return [rebar3VersionsListing, originListing]
94869499
}
94879500

94889501
function isStrictVersion() {

src/setup-beam.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,30 @@ async function maybeInstallRebar3(rebar3Spec) {
168168
}
169169

170170
async function getOTPVersion(otpSpec0, osVersion) {
171-
const otpVersions = await getOTPVersions(osVersion)
171+
const [otpVersions, originListing, hexMirrors] = await getOTPVersions(
172+
osVersion,
173+
)
172174
let spec = otpSpec0.replace(/^OTP-/, '')
173175
const versions = otpVersions
174176
const otpVersion = getVersionFromSpec(spec, versions)
177+
175178
if (otpVersion === null) {
176179
throw new Error(
177-
`Requested Erlang/OTP version (${otpSpec0}) not found in version list ` +
178-
"(should you be using option 'version-type': 'strict'?)",
180+
requestedVersionFor('Erlang/OTP', otpSpec0, originListing, hexMirrors),
179181
)
180182
}
181183

182184
return otpVersion // from the reference, for download
183185
}
184186

187+
function requestedVersionFor(tool, version, originListing, mirrors) {
188+
return (
189+
`Requested ${tool} version (${version}) not found in version list, ` +
190+
`at ${originListing}${mirrors ? `, with mirrors ${mirrors}` : ''}; ` +
191+
"should you be using option 'version-type': 'strict'?"
192+
)
193+
}
194+
185195
async function getElixirVersion(exSpec0, otpVersion0) {
186196
const otpVersion = otpVersion0.match(/^([^-]+-)?(.+)$/)[2]
187197
let otpVersionMajor = otpVersion.match(/^([^.]+).*$/)[1]
@@ -192,15 +202,15 @@ async function getElixirVersion(exSpec0, otpVersion0) {
192202
otpVersionMajor = userSuppliedOtp
193203
}
194204

195-
const [otpVersionsForElixirMap, elixirVersions] = await getElixirVersions()
205+
const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
206+
await getElixirVersions()
196207
const spec = exSpec0.replace(/-otp-.*$/, '')
197208
const versions = elixirVersions
198209
const elixirVersionFromSpec = getVersionFromSpec(spec, versions)
199210

200211
if (elixirVersionFromSpec === null) {
201212
throw new Error(
202-
`Requested Elixir version (${exSpec0}) not found in version list ` +
203-
"(should you be using option 'version-type': 'strict'?)",
213+
requestedVersionFor('Elixir', exSpec0, originListing, hexMirrors),
204214
)
205215
}
206216

@@ -231,30 +241,26 @@ async function getElixirVersion(exSpec0, otpVersion0) {
231241
}
232242

233243
async function getGleamVersion(gleamSpec0) {
234-
const gleamVersions = await getGleamVersions()
244+
const [gleamVersions, originListing] = await getGleamVersions()
235245
const spec = gleamSpec0
236246
const versions = gleamVersions
237247
const gleamVersion = getVersionFromSpec(spec, versions)
248+
238249
if (gleamVersion === null) {
239-
throw new Error(
240-
`Requested Gleam version (${gleamSpec0}) not found in version list ` +
241-
"(should you be using option 'version-type': 'strict'?)",
242-
)
250+
throw new Error(requestedVersionFor('Gleam', gleamSpec0, originListing))
243251
}
244252

245253
return maybePrependWithV(gleamVersion)
246254
}
247255

248256
async function getRebar3Version(r3Spec) {
249-
const rebar3Versions = await getRebar3Versions()
257+
const [rebar3Versions, originListing] = await getRebar3Versions()
250258
const spec = r3Spec
251259
const versions = rebar3Versions
252260
const rebar3Version = getVersionFromSpec(spec, versions)
261+
253262
if (rebar3Version === null) {
254-
throw new Error(
255-
`Requested rebar3 version (${r3Spec}) not found in version list ` +
256-
"(should you be using option 'version-type': 'strict'?)",
257-
)
263+
throw new Error(requestedVersionFor('rebar3', r3Spec, originListing))
258264
}
259265

260266
return rebar3Version
@@ -263,10 +269,12 @@ async function getRebar3Version(r3Spec) {
263269
async function getOTPVersions(osVersion) {
264270
let otpVersionsListings
265271
let originListing
272+
let hexMirrors = null
266273
if (process.platform === 'linux') {
267274
originListing = `/builds/otp/${getRunnerOSArchitecture()}/${osVersion}/builds.txt`
275+
hexMirrors = hexMirrorsInput()
268276
otpVersionsListings = await doWithMirrors({
269-
hexMirrors: hexMirrorsInput(),
277+
hexMirrors,
270278
actionTitle: `fetch ${originListing}`,
271279
action: async (hexMirror) => {
272280
return get(`${hexMirror}${originListing}`, [])
@@ -278,7 +286,10 @@ async function getOTPVersions(osVersion) {
278286
otpVersionsListings = await get(originListing, [1, 2, 3])
279287
}
280288

281-
debugLog(`OTP versions listings from ${originListing}`, otpVersionsListings)
289+
debugLog(
290+
`OTP versions listings from ${originListing}, mirrors ${hexMirrors}`,
291+
otpVersionsListings,
292+
)
282293

283294
const otpVersions = {}
284295
if (process.platform === 'linux') {
@@ -312,15 +323,19 @@ async function getOTPVersions(osVersion) {
312323
})
313324
}
314325

315-
debugLog(`OTP versions from ${originListing}`, JSON.stringify(otpVersions))
326+
debugLog(
327+
`OTP versions from ${originListing}, mirrors ${hexMirrors}`,
328+
JSON.stringify(otpVersions),
329+
)
316330

317-
return otpVersions
331+
return [otpVersions, originListing, hexMirrors]
318332
}
319333

320334
async function getElixirVersions() {
321335
const originListing = '/builds/elixir/builds.txt'
336+
const hexMirrors = hexMirrorsInput()
322337
const elixirVersionsListings = await doWithMirrors({
323-
hexMirrors: hexMirrorsInput(),
338+
hexMirrors,
324339
actionTitle: `fetch ${originListing}`,
325340
action: async (hexMirror) => {
326341
return get(`${hexMirror}${originListing}`, [])
@@ -346,14 +361,13 @@ async function getElixirVersions() {
346361
elixirVersions[elixirVersion] = elixirVersion
347362
})
348363

349-
return [otpVersionsForElixirMap, elixirVersions]
364+
return [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors]
350365
}
351366

352367
async function getGleamVersions() {
353-
const resultJSONs = await get(
354-
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100',
355-
[1, 2, 3],
356-
)
368+
const originListing =
369+
'https://api.github.com/repos/gleam-lang/gleam/releases?per_page=100'
370+
const resultJSONs = await get(originListing, [1, 2, 3])
357371
const gleamVersionsListing = {}
358372
resultJSONs.forEach((resultJSON) => {
359373
resultJSON
@@ -365,14 +379,13 @@ async function getGleamVersions() {
365379
})
366380
})
367381

368-
return gleamVersionsListing
382+
return [gleamVersionsListing, originListing]
369383
}
370384

371385
async function getRebar3Versions() {
372-
const resultJSONs = await get(
373-
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100',
374-
[1, 2, 3],
375-
)
386+
const originListing =
387+
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100'
388+
const resultJSONs = await get(originListing, [1, 2, 3])
376389
const rebar3VersionsListing = {}
377390
resultJSONs.forEach((resultJSON) => {
378391
resultJSON
@@ -382,7 +395,7 @@ async function getRebar3Versions() {
382395
})
383396
})
384397

385-
return rebar3VersionsListing
398+
return [rebar3VersionsListing, originListing]
386399
}
387400

388401
function isStrictVersion() {

0 commit comments

Comments
 (0)