Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: fail at getting uuid more gracefully #1702

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backend/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()).join(","));
};

const getCards = () => {
if (!cards) {
Expand Down
15 changes: 9 additions & 6 deletions scripts/download_allsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
12 changes: 8 additions & 4 deletions scripts/download_booster_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down Expand Up @@ -77,8 +77,12 @@ const getCard = (cardCode) => {

const getUuid = (cardCode) => {
const [setCode, cardNumber] = cardCode.split(":");
const { cardsByNumber } = getSet(setCode.toUpperCase());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line here was the gotcha - destructuring undefined was causing an error to be thrown in CI

I don't know why the set would not be found, maybe that's an error which should throw, as it shows your data is somehow really wrong.

return cardsByNumber[cardNumber] || cardsByNumber[parseInt(cardNumber)] || cardsByNumber[cardNumber.toLowerCase()];
const set = getSet(setCode);
if (!set) {
logger.warn("unknown setCode: " + setCode.toUpperCase());
return;
}
return set.cardsByNumber[cardNumber] || set.cardsByNumber[parseInt(cardNumber)] || set.cardsByNumber[cardNumber.toLowerCase()];
};

module.exports = fetch;
Expand Down
1 change: 1 addition & 0 deletions scripts/update_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const updateDatabase = () => {
}
} catch (err) {
logger.error(`Error while integrating the file ${filePath}: ${err.stack}`);
console.log("JUNK:", fs.readFileSync(filePath, "UTF-8"));
}
});
}
Expand Down
Loading