feat: display stack trace on winston.error

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 55f8f99bcd
commit e80379dc0e

@ -81,7 +81,7 @@ web.install = function (port) {
async.parallel([compileLess, compileJS, copyCSS, loadDefaults], function (err) { async.parallel([compileLess, compileJS, copyCSS, loadDefaults], function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
} }
setupRoutes(); setupRoutes();
launchExpress(port); launchExpress(port);
@ -225,12 +225,12 @@ function launch(req, res) {
function compileLess(callback) { function compileLess(callback) {
fs.readFile(path.join(__dirname, '../public/less/install.less'), function (err, style) { fs.readFile(path.join(__dirname, '../public/less/install.less'), function (err, style) {
if (err) { if (err) {
return winston.error('Unable to read LESS install file: ', err); return winston.error('Unable to read LESS install file: ', err.stack);
} }
less.render(style.toString(), function (err, css) { less.render(style.toString(), function (err, css) {
if (err) { if (err) {
return winston.error('Unable to compile LESS: ', err); return winston.error('Unable to compile LESS: ', err.stack);
} }
fs.writeFile(path.join(__dirname, '../public/installer.css'), css.css, callback); fs.writeFile(path.join(__dirname, '../public/installer.css'), css.css, callback);

@ -138,7 +138,7 @@ Analytics.writeData = async function () {
try { try {
await Promise.all(dbQueue); await Promise.all(dbQueue);
} catch (err) { } catch (err) {
winston.error('[analytics] Encountered error while writing analytics to data store', err); winston.error('[analytics] Encountered error while writing analytics to data store', err.stack);
throw err; throw err;
} }
}; };

@ -85,7 +85,7 @@ function activate(plugin) {
}, },
], function (err) { ], function (err) {
if (err) { if (err) {
winston.error('An error occurred during plugin activation', err); winston.error('An error occurred during plugin activation', err.stack);
throw err; throw err;
} }
process.exit(0); process.exit(0);
@ -219,7 +219,7 @@ function info() {
function buildWrapper(targets, options) { function buildWrapper(targets, options) {
build.build(targets, options, function (err) { build.build(targets, options, function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
process.exit(1); process.exit(1);
} }
process.exit(0); process.exit(0);

@ -141,7 +141,7 @@ async function resetPlugin(pluginId) {
throw new Error('plugin-not-active'); throw new Error('plugin-not-active');
} }
} catch (err) { } catch (err) {
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err); winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err.stack);
throw err; throw err;
} }
} }

@ -51,7 +51,7 @@ function setup(initConfig) {
console.log('\n' + separator + '\n'); console.log('\n' + separator + '\n');
if (err) { if (err) {
winston.error('There was a problem completing NodeBB setup', err); winston.error('There was a problem completing NodeBB setup', err.stack);
throw err; throw err;
} else { } else {
if (data.hasOwnProperty('password')) { if (data.hasOwnProperty('password')) {

@ -67,10 +67,9 @@ async function getNotices() {
async function getLatestVersion() { async function getLatestVersion() {
try { try {
const result = await versions.getLatestVersion(); return await versions.getLatestVersion();
return result;
} catch (err) { } catch (err) {
winston.error('[acp] Failed to fetch latest version', err); winston.error('[acp] Failed to fetch latest version', err.stack);
} }
return null; return null;
} }

@ -52,7 +52,7 @@ pubsub.on('sync:node:info:start', async function () {
data.id = os.hostname() + ':' + nconf.get('port'); data.id = os.hostname() + ':' + nconf.get('port');
pubsub.publish('sync:node:info:end', { data: data, id: data.id }); pubsub.publish('sync:node:info:end', { data: data, id: data.id });
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
}); });
@ -99,7 +99,7 @@ async function getGitInfo() {
function get(cmd, callback) { function get(cmd, callback) {
exec(cmd, function (err, stdout) { exec(cmd, function (err, stdout) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
} }
callback(null, stdout ? stdout.replace(/\n$/, '') : 'no-git-info'); callback(null, stdout ? stdout.replace(/\n$/, '') : 'no-git-info');
}); });

@ -12,7 +12,7 @@ logsController.get = async function (req, res) {
try { try {
logs = await meta.logs.get(); logs = await meta.logs.get();
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
res.render('admin/advanced/logs', { res.render('admin/advanced/logs', {
data: validator.escape(logs), data: validator.escape(logs),

@ -52,7 +52,7 @@ async function getPlugins(matching) {
const pluginsData = await plugins.list(matching); const pluginsData = await plugins.list(matching);
return pluginsData || []; return pluginsData || [];
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
return []; return [];
} }
} }

@ -143,7 +143,7 @@ function markAsRead(req, tid) {
if (req.loggedIn) { if (req.loggedIn) {
topics.markAsRead([tid], req.uid, function (err, markedRead) { topics.markAsRead([tid], req.uid, function (err, markedRead) {
if (err) { if (err) {
return winston.error(err); return winston.error(err.stack);
} }
if (markedRead) { if (markedRead) {
topics.pushUnreadCount(req.uid); topics.pushUnreadCount(req.uid);

@ -13,13 +13,13 @@ const PubSub = function () {
subClient.connect(function (err) { subClient.connect(function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
return; return;
} }
subClient.query('LISTEN pubsub', function (err) { subClient.query('LISTEN pubsub', function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
} }
}); });

@ -40,7 +40,7 @@ redisModule.init = function (callback) {
callback = callback || function () { }; callback = callback || function () { };
redisModule.client = connection.connect(nconf.get('redis'), function (err) { redisModule.client = connection.connect(nconf.get('redis'), function (err) {
if (err) { if (err) {
winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err); winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err.stack);
return callback(err); return callback(err);
} }
require('./redis/promisify')(redisModule.client); require('./redis/promisify')(redisModule.client);

@ -58,7 +58,7 @@ connection.connect = function (options, callback) {
if (dbIdx >= 0) { if (dbIdx >= 0) {
cxn.select(dbIdx, function (err) { cxn.select(dbIdx, function (err) {
if (err) { if (err) {
winston.error('NodeBB could not select Redis database. Redis returned the following error', err); winston.error('NodeBB could not select Redis database. Redis returned the following error', err.stack);
throw err; throw err;
} }
}); });

@ -193,7 +193,7 @@ Emailer.send = async function (template, uid, params) {
try { try {
await Emailer.sendToEmail(template, userData.email, userSettings.userLang, params); await Emailer.sendToEmail(template, userData.email, userSettings.userLang, params);
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
}; };
@ -286,7 +286,7 @@ Emailer.sendViaFallback = function (data, callback) {
winston.verbose('[emailer] Sending email to uid ' + data.uid + ' (' + data.to + ')'); winston.verbose('[emailer] Sending email to uid ' + data.uid + ' (' + data.to + ')');
Emailer.fallbackTransport.sendMail(data, function (err) { Emailer.fallbackTransport.sendMail(data, function (err) {
if (err) { if (err) {
winston.error(err); winston.error(err.stack);
} }
callback(); callback();
}); });
@ -322,7 +322,7 @@ async function buildCustomTemplates(config) {
Benchpress.flush(); Benchpress.flush();
winston.verbose('[emailer] Built custom email templates'); winston.verbose('[emailer] Built custom email templates');
} catch (err) { } catch (err) {
winston.error('[emailer] Failed to build custom email templates', err); winston.error('[emailer] Failed to build custom email templates', err.stack);
} }
} }

@ -78,7 +78,7 @@ Flags.init = async function () {
const data = await plugins.fireHook('filter:flags.getFilters', hookData); const data = await plugins.fireHook('filter:flags.getFilters', hookData);
Flags._filters = data.filters; Flags._filters = data.filters;
} catch (err) { } catch (err) {
winston.error('[flags/init] Could not retrieve filters', err); winston.error('[flags/init] Could not retrieve filters', err.stack);
Flags._filters = {}; Flags._filters = {};
} }
}; };

@ -82,7 +82,7 @@ module.exports = function (Groups) {
}); });
} catch (err) { } catch (err) {
if (err && err.message !== '[[error:group-already-exists]]') { if (err && err.message !== '[[error:group-already-exists]]') {
winston.error('[groups.join] Could not create new hidden group', err); winston.error('[groups.join] Could not create new hidden group', err.stack);
throw err; throw err;
} }
} }

@ -607,7 +607,7 @@ install.save = function (server_conf, callback) {
fs.writeFile(serverConfigPath, JSON.stringify(server_conf, null, 4), function (err) { fs.writeFile(serverConfigPath, JSON.stringify(server_conf, null, 4), function (err) {
if (err) { if (err) {
winston.error('Error saving server configuration!', err); winston.error('Error saving server configuration!', err.stack);
return callback(err); return callback(err);
} }

@ -88,7 +88,7 @@ Logger.open = function (value) {
if (stream) { if (stream) {
stream.on('error', function (err) { stream.on('error', function (err) {
winston.error(err); winston.error(err.stack);
}); });
} }
} else { } else {

@ -114,7 +114,7 @@ function beforeBuild(targets, callback) {
}, },
], function (err) { ], function (err) {
if (err) { if (err) {
winston.error('[build] Encountered error preparing for build', err); winston.error('[build] Encountered error preparing for build', err.stack);
return callback(err); return callback(err);
} }
@ -218,7 +218,7 @@ exports.build = function (targets, options, callback) {
}, },
], function (err) { ], function (err) {
if (err) { if (err) {
winston.error('[build] Encountered error during build step', err); winston.error('[build] Encountered error during build step', err.stack);
return callback(err); return callback(err);
} }

@ -44,7 +44,7 @@ function deserialize(config) {
try { try {
deserialized[key] = JSON.parse(config[key] || '[]'); deserialized[key] = JSON.parse(config[key] || '[]');
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
deserialized[key] = defaults[key]; deserialized[key] = defaults[key];
} }
} else { } else {

@ -30,7 +30,7 @@ Errors.writeData = async function () {
await db.sortedSetIncrBy('errors:404', _counters[key], key); await db.sortedSetIncrBy('errors:404', _counters[key], key);
} }
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
}; };

@ -113,7 +113,7 @@ module.exports = function (middleware) {
try { try {
p = utils.slugify(decodeURIComponent(p)); p = utils.slugify(decodeURIComponent(p));
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
p = ''; p = '';
} }
p = validator.escape(String(p)); p = validator.escape(String(p));

@ -326,7 +326,7 @@ Notifications.prune = async function () {
}, { batch: 500, interval: 100 }); }, { batch: 500, interval: 100 });
} catch (err) { } catch (err) {
if (err) { if (err) {
winston.error('Encountered error pruning notifications', err); winston.error('Encountered error pruning notifications', err.stack);
} }
} }
}; };

@ -48,7 +48,7 @@ Data.loadPluginInfo = async function (pluginPath) {
} catch (err) { } catch (err) {
var pluginDir = path.basename(pluginPath); var pluginDir = path.basename(pluginPath);
winston.error('[plugins/' + pluginDir + '] Error in plugin.json or package.json!', err); winston.error('[plugins/' + pluginDir + '] Error in plugin.json or package.json!', err.stack);
throw new Error('[[error:parse-error]]'); throw new Error('[[error:parse-error]]');
} }
return pluginData; return pluginData;

@ -291,7 +291,7 @@ Plugins.showInstalled = async function () {
pluginData.error = false; pluginData.error = false;
return pluginData; return pluginData;
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
} }
const plugins = await Promise.all(pluginPaths.map(file => load(file))); const plugins = await Promise.all(pluginPaths.map(file => load(file)));

@ -33,7 +33,7 @@ module.exports = function (Plugins) {
timeout: 5000, timeout: 5000,
}, function (err, res, body) { }, function (err, res, body) {
if (err) { if (err) {
return winston.error(err); return winston.error(err.stack);
} }
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
winston.error('[plugins.submitUsageData] received ' + res.statusCode + ' ' + body); winston.error('[plugins.submitUsageData] received ' + res.statusCode + ' ' + body);

@ -173,7 +173,7 @@ async function deleteUsers(socket, uids, method) {
try { try {
await Promise.all(uids.map(uid => doDelete(uid))); await Promise.all(uids.map(uid => doDelete(uid)));
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
} }

@ -113,7 +113,7 @@ function addProcessHandlers() {
process.on('SIGINT', shutdown); process.on('SIGINT', shutdown);
process.on('SIGHUP', restart); process.on('SIGHUP', restart);
process.on('uncaughtException', function (err) { process.on('uncaughtException', function (err) {
winston.error(err); winston.error(err.stack);
require('./meta').js.killMinifier(); require('./meta').js.killMinifier();
shutdown(1); shutdown(1);

@ -35,7 +35,7 @@ Digest.execute = async function (payload) {
}); });
winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. Sending emails; this may take some time...'); winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. Sending emails; this may take some time...');
} catch (err) { } catch (err) {
winston.error('[user/jobs] Could not send digests (' + payload.interval + ')', err); winston.error('[user/jobs] Could not send digests (' + payload.interval + ')', err.stack);
throw err; throw err;
} }
}; };
@ -139,7 +139,7 @@ Digest.send = async function (data) {
showUnsubscribe: true, showUnsubscribe: true,
}); });
} catch (err) { } catch (err) {
winston.error('[user/jobs] Could not send digest email', err); winston.error('[user/jobs] Could not send digest email', err.stack);
} }
if (data.interval !== 'alltime') { if (data.interval !== 'alltime') {

@ -190,7 +190,7 @@ UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicD
await notifications.push(notifObj, followers); await notifications.push(notifObj, followers);
} catch (err) { } catch (err) {
winston.error(err); winston.error(err.stack);
} }
}; };

@ -48,9 +48,9 @@ module.exports.app = app;
server.on('error', function (err) { server.on('error', function (err) {
if (err.code === 'EADDRINUSE') { if (err.code === 'EADDRINUSE') {
winston.error('NodeBB address in use, exiting...', err); winston.error('NodeBB address in use, exiting...', err.stack);
} else { } else {
winston.error(err); winston.error(err.stack);
} }
throw err; throw err;
@ -265,7 +265,7 @@ function listen(callback) {
oldUmask = process.umask('0000'); oldUmask = process.umask('0000');
module.exports.testSocket(socketPath, function (err) { module.exports.testSocket(socketPath, function (err) {
if (err) { if (err) {
winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')', err); winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')', err.stack);
throw err; throw err;
} }

Loading…
Cancel
Save