From 46defdb77b42b090627de1a95f25771c4eed9943 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 9 Nov 2018 02:59:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Improve=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 18 +++++++++++------- src/model/model.ts | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index c242238..8112d6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,17 +12,21 @@ const newPatches: any[] = []; const productData: { [key in Product]?: IProductData } = await model.init(); const productDataEntries = Object.entries(productData) as Array<[Product, IProductData]>; + //Check for new manifest version await Promise.all(productDataEntries.map(async ([product, { manifest, http}]) => { //Check for new manifest version - const { current } = await getManifest(product); - if (current < manifest) { - writeLog(`Product ${product} now has a smaller manifest version ${current}, down from ${manifest}.`); + try { + const { current} = await getManifest(product); + if (current < manifest) { + writeLog(`Product ${product} now has a smaller manifest version ${current}, down from ${manifest}.`); + } else if (current > manifest) { + writeLog(`New manifest version: ${current} instead of ${manifest}`); + model.updateManifestVersion(product, current); + } + } catch (error) { + writeLog(`Could not get manifest for ${product} (previous version was ${manifest}), error message: ${String(error)}`); return; } - if (current > manifest) { - writeLog(`New manifest version: ${current} instead of ${manifest}`); - model.updateManifestVersion(product, current); - } //Check for new HTTP version //TODO diff --git a/src/model/model.ts b/src/model/model.ts index a606c3f..83abba6 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,8 @@ export async function init(): Promise<{ [key in Product]?: IProductData }> { }); //If row does not exist, INSERT into table - await Promise.all(products.filter((product) => output[product] === undefined).map(function(product) { + const missingProducts = products.filter((product) => output[product] === undefined); + await Promise.all(missingProducts.map(function(product) { output[product] = { http: -1, manifest: -1 }; const queryTemplate = `INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES (?, '-1', '-1');`; const query = mysql.format(queryTemplate, [String(product)]);