Skip to content

Commit

Permalink
fix(package): github-release error handling
Browse files Browse the repository at this point in the history
The catch block in getRelease was only handling got errors and
therefore could not handle errors thrown because no or too many
assets were found.
  • Loading branch information
line-o committed Apr 11, 2024
1 parent e7ff9cb commit b39ebbf
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions commands/package/install/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ import { logFailure, logSuccess, logSkipped } from '../../../utility/message.js'
async function getRelease (api, owner, repo, release, assetFilter) {
const tag = release === 'latest' ? release : 'tags/' + release
const path = `repos/${owner}/${repo}/releases/${tag}`
let assets, name
try {
const { assets, name } = await got.get(path, { prefixUrl: api }).json()
const f = assets.filter(assetFilter)
if (!f.length) {
throw Error('no matching asset found')
}
if (f.length > 1) {
throw Error('more than one matching asset found')
}
return {
xarName: f[0].name,
packageContents: f[0].browser_download_url,
releaseName: name
}
({ assets, name } = await got.get(path, { prefixUrl: api }).json())
} catch (e) {
throw Error(`Could not get release from: ${e.options.url}`)
}
const filteredAssets = assets.filter(assetFilter)
if (!filteredAssets.length) {
throw Error('no matching asset found')
}
if (filteredAssets.length > 1) {
throw Error('more than one matching asset found')
}
const asset = filteredAssets[0]
return {
xarName: asset.name,
packageContents: asset.browser_download_url,
releaseName: name
}
}

async function install (db, upload, xarName, contents, registry) {
Expand Down

0 comments on commit b39ebbf

Please sign in to comment.