Try to reduce the extra crap logged when a db query fails

This commit is contained in:
Calvin Montgomery 2018-01-18 19:47:55 -08:00
parent 0f9bc44925
commit 8821de0e7d
2 changed files with 70 additions and 1 deletions

51
src/_gen_cookies.js Normal file
View file

@ -0,0 +1,51 @@
const fs = require('fs');
require('./config').load('config.yaml');
const session = require('./session');
const users = String(fs.readFileSync('/home/calvin/tmp/cytube_startup.txt'))
.split('\n')
.filter(ln => /logged in as/.test(ln))
.map(ln => {
const m = ln.match(/(\S+) logged in as (\S+)/);
return { ip: m[1], name: m[2] };
});
const ip2chan = new Map();
String(fs.readFileSync('/home/calvin/tmp/cytube_startup.txt'))
.split('\n')
.filter(ln => /joined/.test(ln))
.map(ln => {
const m = ln.match(/(\S+) joined (\S+)/);
ip2chan.set(m[1], m[2]);
});
const db = require('./database');
db.init();
function next() {
if (!users.length) return;
const { ip, name } = users.shift();
db.users.getUser(name, (err, u) => {
if (err === 'User does not exist') {
process.nextTick(next);
return;
}
if (err) throw err;
session.genSession(u, Date.now() + 24 * 3600 * 1000, (err, s) => {
if (err) throw err;
if (ip2chan.has(ip)) {
//s = require('cookie-signature').sign(s, 'change-me');
console.log(`${ip}\t${name}\t${s}\t${ip2chan.get(ip)}`);
}
process.nextTick(next);
});
});
}
next();

View file

@ -137,7 +137,25 @@ module.exports.query = function (query, sub, callback) {
process.nextTick(callback, null, res[0]);
}).catch(error => {
queryErrorCount.inc(1);
LOGGER.error('Legacy DB query failed. Query: %s, Substitutions: %j, Error: %s', query, sub, error);
let subs = JSON.stringify(sub);
if (subs.length > 100) {
subs = subs.substring(0, 100) + '...';
}
// Attempt to strip off the beginning of the message which
// contains the entire substituted SQL query (followed by an
// error code)
// Thanks MySQL/MariaDB...
error.message = error.message.replace(/^.* - ER/, 'ER');
LOGGER.error(
'Legacy DB query failed. Query: %s, Substitutions: %s, ' +
'Error: %s',
query,
subs,
error
);
process.nextTick(callback, 'Database failure', null);
}).finally(() => {
end();