1
0
Fork 0

Don't use process.exit, throw an error instead

This commit is contained in:
Chocobozzz 2016-02-07 12:01:40 +01:00
parent a030a9b234
commit ac2f99eb75
5 changed files with 7 additions and 15 deletions

View file

@ -36,9 +36,7 @@ function createDirectoriesIfNotExist () {
try { try {
mkdirp.sync(path.join(__dirname, '..', dir)) mkdirp.sync(path.join(__dirname, '..', dir))
} catch (error) { } catch (error) {
// Do not use logger throw new Error('Cannot create ' + path + ':' + error)
console.error('Cannot create ' + path + ':' + error)
process.exit(0)
} }
} }
} }

View file

@ -16,8 +16,7 @@ var database = {
function connect () { function connect () {
mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
mongoose.connection.on('error', function () { mongoose.connection.on('error', function () {
logger.error('Mongodb connection error.') throw new Error('Mongodb connection error.')
process.exit(0)
}) })
mongoose.connection.on('open', function () { mongoose.connection.on('open', function () {

View file

@ -43,8 +43,7 @@ function create (options, callback) {
// Run a timeout of 30s after which we exit the process // Run a timeout of 30s after which we exit the process
var timeout_webtorrent_process = setTimeout(function () { var timeout_webtorrent_process = setTimeout(function () {
logger.error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.') throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
process.exit()
}, 30000) }, 30000)
ipc.server.on(processKey + '.ready', function () { ipc.server.on(processKey + '.ready', function () {
@ -54,8 +53,7 @@ function create (options, callback) {
}) })
ipc.server.on(processKey + '.exception', function (data) { ipc.server.on(processKey + '.exception', function (data) {
logger.error('Received exception error from webtorrent process.', { exception: data.exception }) throw new Error('Received exception error from webtorrent process.' + data.exception)
process.exit()
}) })
var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true }) var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true })

View file

@ -5,8 +5,7 @@ function webtorrent (args) {
var ipc = require('node-ipc') var ipc = require('node-ipc')
if (args.length !== 3) { if (args.length !== 3) {
console.log('Wrong arguments number: ' + args.length + '/3') throw new Error('Wrong arguments number: ' + args.length + '/3')
process.exit(-1)
} }
var host = args[1] var host = args[1]

View file

@ -18,9 +18,7 @@ var checker = require('./initializers/checker')
var miss = checker.checkConfig() var miss = checker.checkConfig()
if (miss.length !== 0) { if (miss.length !== 0) {
// Do not use logger module throw new Error('Miss some configurations keys : ' + miss)
console.error('Miss some configurations keys.', { miss: miss })
process.exit(0)
} }
checker.createDirectoriesIfNotExist() checker.createDirectoriesIfNotExist()
@ -145,7 +143,7 @@ peertubeCrypto.createCertsIfNotExist(function (err) {
} }
function exitGracefullyOnSignal () { function exitGracefullyOnSignal () {
process.exit() process.exit(-1)
} }
process.on('exit', cleanForExit) process.on('exit', cleanForExit)