diff --git a/app.js b/app.js index 7a222b930c..d1bf1c7c08 100644 --- a/app.js +++ b/app.js @@ -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); }); } diff --git a/loader.js b/loader.js index a2df1b33b7..434e2cce5c 100644 --- a/loader.js +++ b/loader.js @@ -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'); } }); diff --git a/nodebb b/nodebb index c0edb6e39c..d745bb1c6c 100755 --- a/nodebb +++ b/nodebb @@ -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); }); }, }, diff --git a/src/analytics.js b/src/analytics.js index b4922cf184..1f98beb476 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -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); }); diff --git a/src/database/mongo.js b/src/database/mongo.js index fbe4b38a03..04addc07d5 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -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!'); diff --git a/src/database/redis.js b/src/database/redis.js index 13d87c27bd..e45f8f0ef8 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -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; } }); } diff --git a/src/events.js b/src/events.js index ffce83beb4..65a2c36ad8 100644 --- a/src/events.js +++ b/src/events.js @@ -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) { diff --git a/src/flags.js b/src/flags.js index a578accf18..209a5166d5 100644 --- a/src/flags.js +++ b/src/flags.js @@ -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 = {}; } diff --git a/src/groups/membership.js b/src/groups/membership.js index 42c3932805..93dedc57c2 100644 --- a/src/groups/membership.js +++ b/src/groups/membership.js @@ -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(); diff --git a/src/install.js b/src/install.js index aa862f5338..3a69595599 100644 --- a/src/install.js +++ b/src/install.js @@ -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); } diff --git a/src/logger.js b/src/logger.js index d00886b718..632c9b84ca 100644 --- a/src/logger.js +++ b/src/logger.js @@ -88,7 +88,7 @@ Logger.open = function (value) { if (stream) { stream.on('error', function (err) { - winston.error(err.message); + winston.error(err); }); } } else { diff --git a/src/meta/build.js b/src/meta/build.js index 26bec8b5e8..b01a92cb86 100644 --- a/src/meta/build.js +++ b/src/meta/build.js @@ -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); } diff --git a/src/meta/cacheBuster.js b/src/meta/cacheBuster.js index d402fe16f7..f88cebb680 100644 --- a/src/meta/cacheBuster.js +++ b/src/meta/cacheBuster.js @@ -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()); } diff --git a/src/meta/languages.js b/src/meta/languages.js index 3cf1359f4a..3b9f3c3a9e 100644 --- a/src/meta/languages.js +++ b/src/meta/languages.js @@ -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); }; diff --git a/src/middleware/render.js b/src/middleware/render.js index bf3cb03638..851ee1f85f 100644 --- a/src/middleware/render.js +++ b/src/middleware/render.js @@ -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)); diff --git a/src/notifications.js b/src/notifications.js index 919d5a22e4..cbc58dae8e 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -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); }); diff --git a/src/plugins.js b/src/plugins.js index 10db23eb65..cc15650357 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -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); } diff --git a/src/plugins/data.js b/src/plugins/data.js index 1fe4b2e861..b793a365d0 100644 --- a/src/plugins/data.js +++ b/src/plugins/data.js @@ -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]]')); } diff --git a/src/reset.js b/src/reset.js index 3d2fab2e0f..d45c48deb5 100644 --- a/src/reset.js +++ b/src/reset.js @@ -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 { diff --git a/src/user/digest.js b/src/user/digest.js index ffd4f9031e..9a6a81cfcb 100644 --- a/src/user/digest.js +++ b/src/user/digest.js @@ -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.'); } diff --git a/src/webserver.js b/src/webserver.js index bfc472b8ea..dc7c70770c 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -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);