From 68f3e011a13e306804dd08cb0d22aa6381a1b15e Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:02:15 +1200 Subject: [PATCH 1/7] bugfix - fail at getting uuid more gracefully --- scripts/download_booster_rules.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/download_booster_rules.js b/scripts/download_booster_rules.js index f4614466..293846b1 100644 --- a/scripts/download_booster_rules.js +++ b/scripts/download_booster_rules.js @@ -37,9 +37,9 @@ async function fetch() { acc[code] = { balance_colors, totalWeight, - cards: Object.entries(cards).reduce((acc, [cardCode, weigth]) => { + cards: Object.entries(cards).reduce((acc, [cardCode, weight]) => { const uuid = getUuid(cardCode); - acc[uuid] = weigth; + if (uuid) acc[uuid] = weight; return acc; },{}), cardsByColor: Object.entries(cards).reduce((acc, [cardCode]) => { @@ -77,8 +77,12 @@ const getCard = (cardCode) => { const getUuid = (cardCode) => { const [setCode, cardNumber] = cardCode.split(":"); - const { cardsByNumber } = getSet(setCode.toUpperCase()); - return cardsByNumber[cardNumber] || cardsByNumber[parseInt(cardNumber)] || cardsByNumber[cardNumber.toLowerCase()]; + const set = getSet(setCode.toUpperCase()); + if (!set) { + logger.warn("unknown setCode: " + setCode.toUpperCase()); + return; + } + return set.cardsByNumber[cardNumber] || set.cardsByNumber[parseInt(cardNumber)] || set.cardsByNumber[cardNumber.toLowerCase()]; }; module.exports = fetch; From 877645a9e803a65f6c722db8a2624b34488f06dc Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:23:25 +1200 Subject: [PATCH 2/7] add logging on getSet --- backend/data.js | 8 +++++++- scripts/download_booster_rules.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/data.js b/backend/data.js index 551f9019..2e50059d 100644 --- a/backend/data.js +++ b/backend/data.js @@ -49,7 +49,13 @@ const getSets = () => { return sets; }; -const getSet = (setCode) => getSets()[setCode]; +const getSet = (setCode) => { + const set = getSets()[setCode.toUpperCase()]; + if (set) return set; + + console.log("unknown set:", setCode) + console.log("sets:", Object.keys(getSets())) +}; const getCards = () => { if (!cards) { diff --git a/scripts/download_booster_rules.js b/scripts/download_booster_rules.js index 293846b1..417bea9d 100644 --- a/scripts/download_booster_rules.js +++ b/scripts/download_booster_rules.js @@ -77,7 +77,7 @@ const getCard = (cardCode) => { const getUuid = (cardCode) => { const [setCode, cardNumber] = cardCode.split(":"); - const set = getSet(setCode.toUpperCase()); + const set = getSet(setCode); if (!set) { logger.warn("unknown setCode: " + setCode.toUpperCase()); return; From 24637817ee7c923174303f36cf25bd689ad46996 Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:34:03 +1200 Subject: [PATCH 3/7] LINT --- backend/data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/data.js b/backend/data.js index 2e50059d..69564a58 100644 --- a/backend/data.js +++ b/backend/data.js @@ -53,8 +53,8 @@ const getSet = (setCode) => { const set = getSets()[setCode.toUpperCase()]; if (set) return set; - console.log("unknown set:", setCode) - console.log("sets:", Object.keys(getSets())) + console.log("unknown set:", setCode); + console.log("sets:", Object.keys(getSets())); }; const getCards = () => { From 82a04d9db1f15ccb48af04a3ff8f4df18e573a1e Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:35:41 +1200 Subject: [PATCH 4/7] better logging --- backend/data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/data.js b/backend/data.js index 69564a58..5c1a7a1c 100644 --- a/backend/data.js +++ b/backend/data.js @@ -54,7 +54,7 @@ const getSet = (setCode) => { if (set) return set; console.log("unknown set:", setCode); - console.log("sets:", Object.keys(getSets())); + console.log("sets:", Object.keys(getSets()).join(",")); }; const getCards = () => { From 715b8cade74a4e349e221dd7f71a6ec64188199b Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:40:38 +1200 Subject: [PATCH 5/7] MORE LOGGING --- scripts/update_database.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/update_database.js b/scripts/update_database.js index 5b385d40..93b0ebc5 100644 --- a/scripts/update_database.js +++ b/scripts/update_database.js @@ -36,6 +36,7 @@ const updateDatabase = () => { } } catch (err) { logger.error(`Error while integrating the file ${filePath}: ${err.stack}`); + console.log(fs.readFileSync(filePath, "UTF-8")); } }); } From 1e9037d626ce1afb703f8c4f2f05ea12931f1e5d Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:42:32 +1200 Subject: [PATCH 6/7] clearer marking of just files --- scripts/update_database.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_database.js b/scripts/update_database.js index 93b0ebc5..3c3ad99f 100644 --- a/scripts/update_database.js +++ b/scripts/update_database.js @@ -36,7 +36,7 @@ const updateDatabase = () => { } } catch (err) { logger.error(`Error while integrating the file ${filePath}: ${err.stack}`); - console.log(fs.readFileSync(filePath, "UTF-8")); + console.log('JUNK:', fs.readFileSync(filePath, "UTF-8")); } }); } From 804cb12011e443c74e872a3c60cb00cee436aa37 Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 26 Apr 2023 11:52:17 +1200 Subject: [PATCH 7/7] catch error --- scripts/download_allsets.js | 15 +++++++++------ scripts/update_database.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/download_allsets.js b/scripts/download_allsets.js index 6800f29d..62449dc3 100644 --- a/scripts/download_allsets.js +++ b/scripts/download_allsets.js @@ -62,12 +62,15 @@ const download = async () => { logger.info("Checking if AllSets.json is up to date"); const [isUpToDate, version] = await isVersionUpToDate(); if (!isUpToDate) { - await fetchZip(); - logger.info("Fetch AllSets.json finished. Updating the cards and sets data"); - updateDatabase(); - logger.info("Update DB finished"); - fs.writeFileSync(setsVersion, version); - refreshVersion(); + await fetchZip() + .then(() => { + logger.info("Fetch AllSets.json finished. Updating the cards and sets data"); + updateDatabase(); + logger.info("Update DB finished"); + fs.writeFileSync(setsVersion, version); + refreshVersion(); + }) + .catch((err) => logger.error(`Fetch AllSets.json failed. ${err.message}: ${err.stack}`)); } else { logger.info("AllSets.json is up to date"); } diff --git a/scripts/update_database.js b/scripts/update_database.js index 3c3ad99f..e59173e8 100644 --- a/scripts/update_database.js +++ b/scripts/update_database.js @@ -36,7 +36,7 @@ const updateDatabase = () => { } } catch (err) { logger.error(`Error while integrating the file ${filePath}: ${err.stack}`); - console.log('JUNK:', fs.readFileSync(filePath, "UTF-8")); + console.log("JUNK:", fs.readFileSync(filePath, "UTF-8")); } }); }