bin scripts: Delete redundant exception log messages

The exception will cause Node.js to print the error message and stack
trace so there's no point in logging it ourselves.
This commit is contained in:
Richard Hansen 2021-01-17 03:16:01 -05:00 committed by John McLear
parent efdcaae526
commit 0a61767901
3 changed files with 151 additions and 166 deletions

View File

@ -15,84 +15,79 @@ if (process.argv.length !== 2) throw new Error('Use: node bin/checkAllPads.js');
(async () => { (async () => {
await util.promisify(npm.load)({}); await util.promisify(npm.load)({});
try { // initialize the database
// initialize the database require('ep_etherpad-lite/node/utils/Settings');
require('ep_etherpad-lite/node/utils/Settings'); const db = require('ep_etherpad-lite/node/db/DB');
const db = require('ep_etherpad-lite/node/db/DB'); await db.init();
await db.init();
// load modules // load modules
const Changeset = require('ep_etherpad-lite/static/js/Changeset'); const Changeset = require('ep_etherpad-lite/static/js/Changeset');
const padManager = require('ep_etherpad-lite/node/db/PadManager'); const padManager = require('ep_etherpad-lite/node/db/PadManager');
let revTestedCount = 0; let revTestedCount = 0;
// get all pads // get all pads
const res = await padManager.listAllPads(); const res = await padManager.listAllPads();
for (const padId of res.padIDs) { for (const padId of res.padIDs) {
const pad = await padManager.getPad(padId); const pad = await padManager.getPad(padId);
// check if the pad has a pool // check if the pad has a pool
if (pad.pool == null) { if (pad.pool == null) {
console.error(`[${pad.id}] Missing attribute pool`); console.error(`[${pad.id}] Missing attribute pool`);
continue;
}
// create an array with key kevisions
// key revisions always save the full pad atext
const head = pad.getHeadRevisionNumber();
const keyRevisions = [];
for (let rev = 0; rev < head; rev += 100) {
keyRevisions.push(rev);
}
// run through all key revisions
for (const keyRev of keyRevisions) {
// create an array of revisions we need till the next keyRevision or the End
const revisionsNeeded = [];
for (let rev = keyRev; rev <= keyRev + 100 && rev <= head; rev++) {
revisionsNeeded.push(rev);
}
// this array will hold all revision changesets
const revisions = [];
// run through all needed revisions and get them from the database
for (const revNum of revisionsNeeded) {
const revision = await db.get(`pad:${pad.id}:revs:${revNum}`);
revisions[revNum] = revision;
}
// check if the revision exists
if (revisions[keyRev] == null) {
console.error(`[${pad.id}] Missing revision ${keyRev}`);
continue; continue;
} }
// create an array with key kevisions
// key revisions always save the full pad atext // check if there is a atext in the keyRevisions
const head = pad.getHeadRevisionNumber(); let {meta: {atext} = {}} = revisions[keyRev];
const keyRevisions = []; if (atext == null) {
for (let rev = 0; rev < head; rev += 100) { console.error(`[${pad.id}] Missing atext in revision ${keyRev}`);
keyRevisions.push(rev); continue;
} }
// run through all key revisions const apool = pad.pool;
for (const keyRev of keyRevisions) { for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) {
// create an array of revisions we need till the next keyRevision or the End try {
const revisionsNeeded = []; const cs = revisions[rev].changeset;
for (let rev = keyRev; rev <= keyRev + 100 && rev <= head; rev++) { atext = Changeset.applyToAText(cs, atext, apool);
revisionsNeeded.push(rev); revTestedCount++;
} } catch (e) {
console.error(`[${pad.id}] Bad changeset at revision ${rev} - ${e.message}`);
// this array will hold all revision changesets
const revisions = [];
// run through all needed revisions and get them from the database
for (const revNum of revisionsNeeded) {
const revision = await db.get(`pad:${pad.id}:revs:${revNum}`);
revisions[revNum] = revision;
}
// check if the revision exists
if (revisions[keyRev] == null) {
console.error(`[${pad.id}] Missing revision ${keyRev}`);
continue;
}
// check if there is a atext in the keyRevisions
let {meta: {atext} = {}} = revisions[keyRev];
if (atext == null) {
console.error(`[${pad.id}] Missing atext in revision ${keyRev}`);
continue;
}
const apool = pad.pool;
for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) {
try {
const cs = revisions[rev].changeset;
atext = Changeset.applyToAText(cs, atext, apool);
revTestedCount++;
} catch (e) {
console.error(`[${pad.id}] Bad changeset at revision ${rev} - ${e.message}`);
}
} }
} }
} }
if (revTestedCount === 0) {
throw new Error('No revisions tested');
}
console.log(`Finished: Tested ${revTestedCount} revisions`);
} catch (err) {
console.trace(err);
throw err;
} }
if (revTestedCount === 0) {
throw new Error('No revisions tested');
}
console.log(`Finished: Tested ${revTestedCount} revisions`);
})(); })();

View File

@ -19,74 +19,69 @@ let checkRevisionCount = 0;
(async () => { (async () => {
await util.promisify(npm.load)({}); await util.promisify(npm.load)({});
try { // initialize database
// initialize database require('ep_etherpad-lite/node/utils/Settings');
require('ep_etherpad-lite/node/utils/Settings'); const db = require('ep_etherpad-lite/node/db/DB');
const db = require('ep_etherpad-lite/node/db/DB'); await db.init();
await db.init();
// load modules // load modules
const Changeset = require('ep_etherpad-lite/static/js/Changeset'); const Changeset = require('ep_etherpad-lite/static/js/Changeset');
const padManager = require('ep_etherpad-lite/node/db/PadManager'); const padManager = require('ep_etherpad-lite/node/db/PadManager');
const exists = await padManager.doesPadExists(padId); const exists = await padManager.doesPadExists(padId);
if (!exists) throw new Error('Pad does not exist'); if (!exists) throw new Error('Pad does not exist');
// get the pad // get the pad
const pad = await padManager.getPad(padId); const pad = await padManager.getPad(padId);
// create an array with key revisions // create an array with key revisions
// key revisions always save the full pad atext // key revisions always save the full pad atext
const head = pad.getHeadRevisionNumber(); const head = pad.getHeadRevisionNumber();
const keyRevisions = []; const keyRevisions = [];
for (let rev = 0; rev < head; rev += 100) { for (let rev = 0; rev < head; rev += 100) {
keyRevisions.push(rev); keyRevisions.push(rev);
}
// run through all key revisions
for (let keyRev of keyRevisions) {
keyRev = parseInt(keyRev);
// create an array of revisions we need till the next keyRevision or the End
const revisionsNeeded = [];
for (let rev = keyRev; rev <= keyRev + 100 && rev <= head; rev++) {
revisionsNeeded.push(rev);
} }
// run through all key revisions // this array will hold all revision changesets
for (let keyRev of keyRevisions) { const revisions = [];
keyRev = parseInt(keyRev);
// create an array of revisions we need till the next keyRevision or the End
const revisionsNeeded = [];
for (let rev = keyRev; rev <= keyRev + 100 && rev <= head; rev++) {
revisionsNeeded.push(rev);
}
// this array will hold all revision changesets // run through all needed revisions and get them from the database
const revisions = []; for (const revNum of revisionsNeeded) {
const revision = await db.get(`pad:${padId}:revs:${revNum}`);
revisions[revNum] = revision;
}
// run through all needed revisions and get them from the database // check if the pad has a pool
for (const revNum of revisionsNeeded) { if (pad.pool == null) throw new Error('Attribute pool is missing');
const revision = await db.get(`pad:${padId}:revs:${revNum}`);
revisions[revNum] = revision;
}
// check if the pad has a pool // check if there is an atext in the keyRevisions
if (pad.pool == null) throw new Error('Attribute pool is missing'); let {meta: {atext} = {}} = revisions[keyRev] || {};
if (atext == null) {
console.error(`No atext in key revision ${keyRev}`);
continue;
}
// check if there is an atext in the keyRevisions const apool = pad.pool;
let {meta: {atext} = {}} = revisions[keyRev] || {};
if (atext == null) { for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) {
console.error(`No atext in key revision ${keyRev}`); checkRevisionCount++;
try {
const cs = revisions[rev].changeset;
atext = Changeset.applyToAText(cs, atext, apool);
} catch (e) {
console.error(`Bad changeset at revision ${rev} - ${e.message}`);
continue; continue;
} }
const apool = pad.pool;
for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) {
checkRevisionCount++;
try {
const cs = revisions[rev].changeset;
atext = Changeset.applyToAText(cs, atext, apool);
} catch (e) {
console.error(`Bad changeset at revision ${rev} - ${e.message}`);
continue;
}
}
console.log(`Finished: Checked ${checkRevisionCount} revisions`);
} }
} catch (err) { console.log(`Finished: Checked ${checkRevisionCount} revisions`);
console.trace(err);
throw err;
} }
})(); })();

View File

@ -21,54 +21,49 @@ const util = require('util');
(async () => { (async () => {
await util.promisify(npm.load)({}); await util.promisify(npm.load)({});
try { // initialize database
// initialize database require('ep_etherpad-lite/node/utils/Settings');
require('ep_etherpad-lite/node/utils/Settings'); const db = require('ep_etherpad-lite/node/db/DB');
const db = require('ep_etherpad-lite/node/db/DB'); await db.init();
await db.init();
// load extra modules // load extra modules
const dirtyDB = require('ep_etherpad-lite/node_modules/dirty'); const dirtyDB = require('ep_etherpad-lite/node_modules/dirty');
const padManager = require('ep_etherpad-lite/node/db/PadManager'); const padManager = require('ep_etherpad-lite/node/db/PadManager');
// initialize output database // initialize output database
const dirty = dirtyDB(`${padId}.db`); const dirty = dirtyDB(`${padId}.db`);
// Promise wrapped get and set function // Promise wrapped get and set function
const wrapped = db.db.db.wrappedDB; const wrapped = db.db.db.wrappedDB;
const get = util.promisify(wrapped.get.bind(wrapped)); const get = util.promisify(wrapped.get.bind(wrapped));
const set = util.promisify(dirty.set.bind(dirty)); const set = util.promisify(dirty.set.bind(dirty));
// array in which required key values will be accumulated // array in which required key values will be accumulated
const neededDBValues = [`pad:${padId}`]; const neededDBValues = [`pad:${padId}`];
// get the actual pad object // get the actual pad object
const pad = await padManager.getPad(padId); const pad = await padManager.getPad(padId);
// add all authors // add all authors
neededDBValues.push(...pad.getAllAuthors().map((author) => `globalAuthor:${author}`)); neededDBValues.push(...pad.getAllAuthors().map((author) => `globalAuthor:${author}`));
// add all revisions // add all revisions
for (let rev = 0; rev <= pad.head; ++rev) { for (let rev = 0; rev <= pad.head; ++rev) {
neededDBValues.push(`pad:${padId}:revs:${rev}`); neededDBValues.push(`pad:${padId}:revs:${rev}`);
}
// add all chat values
for (let chat = 0; chat <= pad.chatHead; ++chat) {
neededDBValues.push(`pad:${padId}:chat:${chat}`);
}
for (const dbkey of neededDBValues) {
let dbvalue = await get(dbkey);
if (dbvalue && typeof dbvalue !== 'object') {
dbvalue = JSON.parse(dbvalue);
}
await set(dbkey, dbvalue);
}
console.log('finished');
} catch (err) {
console.error(err);
throw err;
} }
// add all chat values
for (let chat = 0; chat <= pad.chatHead; ++chat) {
neededDBValues.push(`pad:${padId}:chat:${chat}`);
}
for (const dbkey of neededDBValues) {
let dbvalue = await get(dbkey);
if (dbvalue && typeof dbvalue !== 'object') {
dbvalue = JSON.parse(dbvalue);
}
await set(dbkey, dbvalue);
}
console.log('finished');
})(); })();