]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Don't use process.exit, throw an error instead
authorChocobozzz <florian.bigard@gmail.com>
Sun, 7 Feb 2016 11:01:40 +0000 (12:01 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 7 Feb 2016 11:01:40 +0000 (12:01 +0100)
initializers/checker.js
initializers/database.js
lib/webtorrent.js
lib/webtorrentProcess.js
server.js

index 9a7d04ed4a4d46f1db1415e51e538023bb6014d8..ec7bc0ad2ff14d32d1b55bab385f5a704b01436d 100644 (file)
@@ -36,9 +36,7 @@ function createDirectoriesIfNotExist () {
     try {
       mkdirp.sync(path.join(__dirname, '..', dir))
     } catch (error) {
-      // Do not use logger
-      console.error('Cannot create ' + path + ':' + error)
-      process.exit(0)
+      throw new Error('Cannot create ' + path + ':' + error)
     }
   }
 }
index 6e3f11df3969474f942bdd23a6408884434f3b58..a917442ec877231d88d6d114368509894e244f1d 100644 (file)
@@ -16,8 +16,7 @@ var database = {
 function connect () {
   mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
   mongoose.connection.on('error', function () {
-    logger.error('Mongodb connection error.')
-    process.exit(0)
+    throw new Error('Mongodb connection error.')
   })
 
   mongoose.connection.on('open', function () {
index 5f10322a5d82953c026f9976eed9373cd50af615..cb641feada355df5958aaa33b7bd59f89f8b91d6 100644 (file)
@@ -43,8 +43,7 @@ function create (options, callback) {
 
     // Run a timeout of 30s after which we exit the process
     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.')
-      process.exit()
+      throw new Error('Timeout : cannot run the webtorrent process. Please ensure you have electron-prebuilt npm package installed with xvfb-run.')
     }, 30000)
 
     ipc.server.on(processKey + '.ready', function () {
@@ -54,8 +53,7 @@ function create (options, callback) {
     })
 
     ipc.server.on(processKey + '.exception', function (data) {
-      logger.error('Received exception error from webtorrent process.', { exception: data.exception })
-      process.exit()
+      throw new Error('Received exception error from webtorrent process.' + data.exception)
     })
 
     var webtorrent_process = spawn(pathUtils.join(__dirname, 'webtorrentProcess.js'), host, port, { detached: true })
index 96ebf9d023b3a48e3e0dd0c7ce5e8dd60008ccf6..7ba2dd3d9f6d1d175c7946ec88428b7b9b2d19ac 100644 (file)
@@ -5,8 +5,7 @@ function webtorrent (args) {
   var ipc = require('node-ipc')
 
   if (args.length !== 3) {
-    console.log('Wrong arguments number: ' + args.length + '/3')
-    process.exit(-1)
+    throw new Error('Wrong arguments number: ' + args.length + '/3')
   }
 
   var host = args[1]
index 6312a4048026332ed87d0bcd70fe42589e1b0213..c971982b37a253297c4a9589128a2f2a60fd718e 100644 (file)
--- a/server.js
+++ b/server.js
@@ -18,9 +18,7 @@ var checker = require('./initializers/checker')
 
 var miss = checker.checkConfig()
 if (miss.length !== 0) {
-  // Do not use logger module
-  console.error('Miss some configurations keys.', { miss: miss })
-  process.exit(0)
+  throw new Error('Miss some configurations keys : ' + miss)
 }
 
 checker.createDirectoriesIfNotExist()
@@ -145,7 +143,7 @@ peertubeCrypto.createCertsIfNotExist(function (err) {
     }
 
     function exitGracefullyOnSignal () {
-      process.exit()
+      process.exit(-1)
     }
 
     process.on('exit', cleanForExit)