Merge pull request #1451 from mempool/nymkappa/bugfix/handle-crash-pool-parser

If pool slug does not exist, generate one on the fly, avoid crash
This commit is contained in:
softsimon 2022-03-25 19:11:46 +04:00 committed by GitHub
commit 7f6c8fdbac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@ interface Pool {
}
class PoolsParser {
slugWarnFlag = false;
/**
* Parse the pools.json file, consolidate the data and dump it into the database
*/
@ -93,7 +95,22 @@ class PoolsParser {
}
const finalPoolName = poolNames[i].replace(`'`, `''`); // To support single quote in names when doing db queries
const slug = poolsJson['slugs'][poolNames[i]];
let slug: string | undefined;
try {
slug = poolsJson['slugs'][poolNames[i]];
} catch (e) {
if (this.slugWarnFlag === false) {
logger.warn(`pools.json does not seem to contain the 'slugs' object`);
this.slugWarnFlag = true;
}
}
if (slug === undefined) {
// Only keep alphanumerical
slug = poolNames[i].replace(/[^a-z0-9]/gi,'').toLowerCase();
logger.debug(`No slug found for '${poolNames[i]}', generating it => '${slug}'`);
}
if (existingPools.find((pool) => pool.name === poolNames[i]) !== undefined) {
finalPoolDataUpdate.push({