Browse Source

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

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

Co-authored-by: Samuel Attard <[email protected]>

* build: improve logging on http errors during release process (again) (#43757)

Co-authored-by: Samuel Attard <[email protected]>

* build: improve logging on http errors during release process (again, but more) (#43758)

Co-authored-by: Samuel Attard <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <[email protected]>
trop[bot] 7 months ago
parent
commit
4b30a2e1d7
3 changed files with 37 additions and 7 deletions
  1. 13 3
      script/release/get-asset.js
  2. 7 2
      script/release/get-url-hash.js
  3. 17 2
      script/release/release.js

+ 13 - 3
script/release/get-asset.js

@@ -22,17 +22,27 @@ async function getAssetContents (repo, assetId) {
   const response = await got(url, {
     followRedirect: false,
     method: 'HEAD',
-    headers
+    headers,
+    throwHttpErrors: false
   });
+
+  if (response.statusCode !== 302 && response.statusCode !== 301) {
+    console.error('Failed to HEAD github asset contents for redirect: ' + url);
+    throw new Error('Unexpected status HEAD\'ing github asset for redirect: ' + response.statusCode);
+  }
+
   if (!response.headers.location) {
     console.error(response.headers, `${response.body}`.slice(0, 300));
     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.statusCode !== 200) {
     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.statusCode}`);
   }
 
   return fileResponse.body;

+ 7 - 2
script/release/get-url-hash.js

@@ -15,8 +15,13 @@ module.exports = async function getUrlHash (targetUrl, algorithm = 'sha256', att
     search: search.toString()
   });
   try {
-    const resp = await got(functionUrl);
-    if (resp.statusCode !== 200) throw new Error('non-200 status code received from hasher function');
+    const resp = await got(functionUrl, {
+      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');
 
     return resp.body.trim();

+ 17 - 2
script/release/release.js

@@ -393,9 +393,15 @@ async function verifyDraftGitHubReleaseAssets (release) {
     const response = await got(url, {
       followRedirect: false,
       method: 'HEAD',
-      headers
+      headers,
+      throwHttpErrors: false
     });
 
+    if (response.statusCode !== 302 && response.statusCode !== 301) {
+      console.error('Failed to HEAD github asset: ' + url);
+      throw new Error('Unexpected status HEAD\'ing github asset: ' + response.statusCode);
+    }
+
     return { url: response.headers.location, file: asset.name };
   })).catch(err => {
     console.error(`${fail} Error downloading files from GitHub`, err);
@@ -406,7 +412,16 @@ async function verifyDraftGitHubReleaseAssets (release) {
 }
 
 async function getShaSumMappingFromUrl (shaSumFileUrl, fileNamePrefix) {
-  const response = await got(shaSumFileUrl);
+  const response = await got(shaSumFileUrl, {
+    throwHttpErrors: false
+  });
+
+  if (response.statusCode !== 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.statusCode);
+  }
+
   const raw = response.body;
   return raw.split('\n').map(line => line.trim()).filter(Boolean).reduce((map, line) => {
     const [sha, file] = line.replace('  ', ' ').split(' ');