diff --git a/src/child-process.coffee b/src/child-process.coffee index 2e2b4a190..cd21c8a45 100644 --- a/src/child-process.coffee +++ b/src/child-process.coffee @@ -118,6 +118,7 @@ terminate = (childProcess, options = {}, callback) -> spawn = (args...) -> childProcess = crossSpawn.spawn.apply(null, args) + childProcess.spawned = true childProcess.terminated = false killedIntentionally = false terminatedIntentionally = false @@ -140,6 +141,12 @@ spawn = (args...) -> childProcess.emit('error', err) if err ) + childProcess.on('error', (err) -> + if err.syscall.indexOf('spawn') >= 0 + childProcess.spawned = false + childProcess.emit('spawnerror', err) + ) + childProcess.on('exit', (exitStatus, signal) -> childProcess.terminated = true childProcess.killedIntentionally = killedIntentionally diff --git a/src/dredd-command.coffee b/src/dredd-command.coffee index 03a8a0208..bdb8fdea7 100644 --- a/src/dredd-command.coffee +++ b/src/dredd-command.coffee @@ -53,7 +53,7 @@ class DreddCommand # Gracefully terminate server stopServer: (callback) -> - unless @serverProcess? + if not @serverProcess or not @serverProcess.spawned logger.verbose('No backend server process to terminate.') return callback() if @serverProcess.terminated @@ -219,9 +219,9 @@ class DreddCommand @serverProcess.on 'exit', => logger.info('Backend server process exited') - @serverProcess.on 'error', (error) => - logger.error('Command to start backend server process failed, exiting Dredd', error) - @_processExit(2) + @serverProcess.on 'spawnerror', (err) => + logger.error('Command to start backend server process failed, exiting Dredd', err) + @_processExit(1) # Ensure server is not running when dredd exits prematurely somewhere process.on 'beforeExit', => @@ -332,11 +332,9 @@ class DreddCommand exitWithStatus: (error, stats) -> if error logger.error(error.message) if error.message - process.exitCode = 1 return @_processExit(1) if (stats.failures + stats.errors) > 0 - process.exitCode = 1 @_processExit(1) else @_processExit(0)