Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
fix: Return correct exit code when server fails to start
Browse files Browse the repository at this point in the history
  • Loading branch information
michalholasek committed Aug 9, 2017
1 parent c2e9b80 commit fdb9118
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/child-process.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/dredd-command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', =>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fdb9118

Please sign in to comment.