Provide more error information to logs

Provides full stack instead of just message
v1.18.x
Peter Jaszkowiak 7 years ago
parent ec38b18e34
commit e609e497b3

@ -192,7 +192,8 @@ function setup() {
process.stdout.write('\n' + separator + '\n\n');
if (err) {
winston.error('There was a problem completing NodeBB setup: ', err.message);
winston.error('There was a problem completing NodeBB setup', err);
throw err;
} else {
if (data.hasOwnProperty('password')) {
process.stdout.write('An administrative user was automatically created for you:\n');
@ -270,9 +271,10 @@ function activate() {
},
], function (err) {
if (err) {
winston.error(err.message);
winston.error('An error occurred during plugin activation', err);
throw err;
}
process.exit(err ? 1 : 0);
process.exit(0);
});
}

@ -158,8 +158,8 @@ Loader.restart = function () {
fs.readFile(pathToConfig, { encoding: 'utf-8' }, function (err, configFile) {
if (err) {
console.log('Error reading config : ' + err.message);
process.exit();
console.error('Error reading config');
throw err;
}
var conf = JSON.parse(configFile);
@ -240,11 +240,12 @@ fs.open(path.join(__dirname, 'config.json'), 'r', function (err) {
Loader.start,
], function (err) {
if (err) {
console.log('[loader] Error during startup: ' + err.message);
console.error('[loader] Error during startup');
throw err;
}
});
} else {
// No config detected, kickstart web installer
require('child_process').fork('app');
fork('app');
}
});

@ -451,7 +451,8 @@ var commands = {
return upgradeProc.on('close', function (err) {
if (err) {
process.stdout.write('\nError'.red + ': ' + err.message + '\n');
process.stdout.write('Error occurred during upgrade');
throw err;
}
});
}
@ -472,19 +473,21 @@ var commands = {
var upgradeProc = fork(arr);
upgradeProc.on('close', next);
upgradeProc.on('error', next);
},
], function (err) {
if (err) {
process.stdout.write('\nError'.red + ': ' + err.message + '\n');
} else {
var message = 'NodeBB Upgrade Complete!';
// some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count
var columns = process.stdout.columns;
var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' ';
process.stdout.write('OK\n'.green);
process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset);
process.stdout.write('Error occurred during upgrade');
throw err;
}
var message = 'NodeBB Upgrade Complete!';
// some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count
var columns = process.stdout.columns;
var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' ';
process.stdout.write('OK\n'.green);
process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset);
});
},
},

@ -100,7 +100,7 @@ Analytics.writeData = function (callback) {
async.parallel(dbQueue, function (err) {
if (err) {
winston.error('[analytics] Encountered error while writing analytics to data store: ' + err.message);
winston.error('[analytics] Encountered error while writing analytics to data store', err);
}
callback(err);
});

@ -104,7 +104,7 @@ mongoModule.init = function (callback) {
mongoClient.connect(connString, connOptions, function (err, _db) {
if (err) {
winston.error('NodeBB could not connect to your Mongo database. Mongo returned the following error: ' + err.message);
winston.error('NodeBB could not connect to your Mongo database. Mongo returned the following error', err);
return callback(err);
}
@ -164,7 +164,7 @@ mongoModule.createIndices = function (callback) {
async.apply(createIndex, 'objects', { expireAt: 1 }, { expireAfterSeconds: 0, background: true }),
], function (err) {
if (err) {
winston.error('Error creating index ' + err.message);
winston.error('Error creating index', err);
return callback(err);
}
winston.info('[database] Checking database indices done!');

@ -99,8 +99,8 @@ redisModule.connect = function (options) {
if (dbIdx >= 0) {
cxn.select(dbIdx, function (err) {
if (err) {
winston.error('NodeBB could not connect to your Redis database. Redis returned the following error: ' + err.message);
process.exit();
winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err);
throw err;
}
});
}

@ -3,6 +3,7 @@
var async = require('async');
var validator = require('validator');
var winston = require('winston');
var db = require('./database');
var batch = require('./batch');
@ -143,8 +144,8 @@ events.output = function () {
process.stdout.write('\nDisplaying last ten administrative events...\n'.bold);
events.getEvents(0, 9, function (err, events) {
if (err) {
process.stdout.write(' Error '.red + String(err.message).reset);
process.exit(1);
winston.error('Error fetching events', err);
throw err;
}
events.forEach(function (event) {

@ -64,7 +64,7 @@ Flags.init = function (callback) {
},
}, function (err, data) {
if (err) {
winston.error('[flags/init] Could not retrieve filters (error: ' + err.message + ')');
winston.error('[flags/init] Could not retrieve filters', err);
data.filters = {};
}

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

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

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

@ -103,7 +103,7 @@ function beforeBuild(targets, callback) {
async.apply(plugins.prepareForBuild, targets),
], function (err) {
if (err) {
winston.error('[build] Encountered error preparing for build: ' + err.message);
winston.error('[build] Encountered error preparing for build', err);
return callback(err);
}
@ -203,7 +203,7 @@ function build(targets, callback) {
},
], function (err) {
if (err) {
winston.error('[build] Encountered error during build step: ' + err.message);
winston.error('[build] Encountered error during build step', err);
return callback(err);
}

@ -33,7 +33,7 @@ exports.read = function read(callback) {
fs.readFile(filePath, function (err, buffer) {
if (err) {
winston.warn('[cache-buster] could not read cache buster: ' + err.message);
winston.warn('[cache-buster] could not read cache buster', err);
return callback(null, generate());
}

@ -1,6 +1,5 @@
'use strict';
var winston = require('winston');
var path = require('path');
var async = require('async');
var fs = require('fs');
@ -182,11 +181,5 @@ exports.build = function buildLanguages(callback) {
},
getTranslationTree,
writeLanguageFiles,
], function (err) {
if (err) {
winston.error('[build] Language build failed: ' + err.message);
throw err;
}
callback();
});
], callback);
};

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

@ -396,7 +396,7 @@ Notifications.prune = function (callback) {
},
], function (err) {
if (err) {
winston.error('Encountered error pruning notifications: ' + err.message);
winston.error('Encountered error pruning notifications', err);
}
callback(err);
});

@ -63,7 +63,7 @@ Plugins.init = function (nbbApp, nbbMiddleware, callback) {
Plugins.reload(function (err) {
if (err) {
winston.error('[plugins] NodeBB encountered a problem while loading plugins', err.message);
winston.error('[plugins] NodeBB encountered a problem while loading plugins', err);
return callback(err);
}
@ -132,7 +132,7 @@ Plugins.reloadRoutes = function (callback) {
var controllers = require('./controllers');
Plugins.fireHook('static:app.load', { app: app, router: router, middleware: middleware, controllers: controllers }, function (err) {
if (err) {
winston.error('[plugins] Encountered error while executing post-router plugins hooks: ' + err.message);
winston.error('[plugins] Encountered error while executing post-router plugins hooks', err);
return callback(err);
}
@ -218,7 +218,7 @@ Plugins.list = function (matching, callback) {
json: true,
}, function (err, res, body) {
if (err) {
winston.error('Error parsing plugins : ' + err.message);
winston.error('Error parsing plugins', err);
return callback(err);
}

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

@ -13,8 +13,8 @@ var Reset = {};
Reset.reset = function (callback) {
db.init(function (err) {
if (err) {
winston.error(err.message);
process.exit(1);
winston.error(err);
throw err;
}
if (nconf.get('t')) {
@ -50,7 +50,7 @@ Reset.reset = function (callback) {
if (!err) {
winston.info('[reset] Reset complete.');
} else {
winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err.message);
winston.error('[reset] Errors were encountered while resetting your forum settings: %s', err);
}
callback();
@ -141,7 +141,7 @@ function resetPlugin(pluginId, callback) {
},
], function (err) {
if (err) {
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err.message);
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err);
} else if (active) {
winston.info('[reset] Plugin `%s` disabled', pluginId);
} else {

@ -45,7 +45,7 @@ Digest.execute = function (payload, callback) {
},
], function (err, count) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message);
winston.error('[user/jobs] Could not send digests (' + payload.interval + ')', err);
} else {
winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + count + ' email(s) sent.');
}

@ -43,13 +43,13 @@ if (nconf.get('ssl')) {
module.exports.server = server;
server.on('error', function (err) {
winston.error(err);
if (err.code === 'EADDRINUSE') {
winston.error('NodeBB address in use, exiting...');
process.exit(1);
winston.error('NodeBB address in use, exiting...', err);
} else {
throw err;
winston.error(err);
}
throw err;
});
module.exports.listen = function (callback) {
@ -301,13 +301,12 @@ function listen(callback) {
if (isSocket) {
oldUmask = process.umask('0000');
module.exports.testSocket(socketPath, function (err) {
if (!err) {
server.listen.apply(server, args);
} else {
winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')');
winston.error('[startup] ' + err.message);
process.exit();
if (err) {
winston.error('[startup] NodeBB was unable to secure domain socket access (' + socketPath + ')', err);
throw err;
}
server.listen.apply(server, args);
});
} else {
server.listen.apply(server, args);

Loading…
Cancel
Save