build: improve logging on http errors during release process (#43756)

This commit is contained in:
Samuel Attard 2024-09-17 14:30:51 -07:00 committed by GitHub
parent 233724fe00
commit 10ba87a85e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 6 deletions

View file

@ -22,14 +22,29 @@ async function getAssetContents (repo, assetId) {
const response = await got(url, { const response = await got(url, {
followRedirect: false, followRedirect: false,
method: 'HEAD', method: 'HEAD',
headers headers,
throwHttpErrors: false
}); });
if (response.status !== 302 && response.status !== 301) {
console.error('Failed to HEAD github asset contents for redirect: ' + url);
throw new Error('Unexpected status HEAD\'ing github asset: ' + response.status);
}
if (!response.headers.location) { if (!response.headers.location) {
console.error(response.headers, `${response.body}`.slice(0, 300)); console.error(response.headers, `${response.body}`.slice(0, 300));
throw new Error(`cannot find asset[${assetId}], asset download did not redirect`); throw new Error(`cannot find asset[${assetId}], asset download did not redirect`);
} }
const fileResponse = await got(response.headers.location); const fileResponse = await got(response.headers.location, {
throwHttpErrors: false
});
if (fileResponse.status !== 200) {
fileResponse.error(`Failed to download github asset contents: ${url} (via: ${response.headers.location})`);
throw new Error('Unexpected status fetching github asset: ' + fileResponse.status);
}
if (fileResponse.statusCode !== 200) { if (fileResponse.statusCode !== 200) {
console.error(fileResponse.headers, `${fileResponse.body}`.slice(0, 300)); console.error(fileResponse.headers, `${fileResponse.body}`.slice(0, 300));
throw new Error(`cannot download asset[${assetId}] from ${response.headers.location}, got status: ${fileResponse.status}`); throw new Error(`cannot download asset[${assetId}] from ${response.headers.location}, got status: ${fileResponse.status}`);

View file

@ -15,8 +15,13 @@ module.exports = async function getUrlHash (targetUrl, algorithm = 'sha256', att
search: search.toString() search: search.toString()
}); });
try { try {
const resp = await got(functionUrl); const resp = await got(functionUrl, {
if (resp.statusCode !== 200) throw new Error('non-200 status code received from hasher function'); throwHttpErrors: false
});
if (resp.statusCode !== 200) {
console.error('bad hasher function response:', resp.body.trim());
throw new Error('non-200 status code received from hasher function');
}
if (!resp.body) throw new Error('Successful lambda call but failed to get valid hash'); if (!resp.body) throw new Error('Successful lambda call but failed to get valid hash');
return resp.body.trim(); return resp.body.trim();

View file

@ -397,9 +397,15 @@ async function verifyDraftGitHubReleaseAssets (release) {
const response = await got(url, { const response = await got(url, {
followRedirect: false, followRedirect: false,
method: 'HEAD', method: 'HEAD',
headers headers,
throwHttpErrors: false
}); });
if (response.status !== 200) {
console.error('Failed to HEAD github asset: ' + url);
throw new Error('Unexpected status HEAD\'ing github asset: ' + response.status);
}
return { url: response.headers.location, file: asset.name }; return { url: response.headers.location, file: asset.name };
})).catch(err => { })).catch(err => {
console.error(`${fail} Error downloading files from GitHub`, err); console.error(`${fail} Error downloading files from GitHub`, err);
@ -410,7 +416,16 @@ async function verifyDraftGitHubReleaseAssets (release) {
} }
async function getShaSumMappingFromUrl (shaSumFileUrl, fileNamePrefix) { async function getShaSumMappingFromUrl (shaSumFileUrl, fileNamePrefix) {
const response = await got(shaSumFileUrl); const response = await got(shaSumFileUrl, {
throwHttpErrors: false
});
if (response.status !== 200) {
console.error('Failed to fetch SHASUM mapping: ' + shaSumFileUrl);
console.error('Bad SHASUM mapping response: ' + response.body.trim());
throw new Error('Unexpected status fetching SHASUM mapping: ' + response.status);
}
const raw = response.body; const raw = response.body;
return raw.split('\n').map(line => line.trim()).filter(Boolean).reduce((map, line) => { return raw.split('\n').map(line => line.trim()).filter(Boolean).reduce((map, line) => {
const [sha, file] = line.replace(' ', ' ').split(' '); const [sha, file] = line.replace(' ', ' ').split(' ');