Guard against missing stdout/stderr

This commit is contained in:
Kevin Sawicki
2015-07-06 17:33:55 -07:00
parent f4284b91ea
commit b371b2f0c9
2 changed files with 20 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
_ = require 'underscore-plus'
{fork} = require 'child_process'
ChildProcess = require 'child_process'
{Emitter} = require 'emissary'
Grim = require 'grim'
@@ -83,7 +83,7 @@ class Task
taskPath = taskPath.replace(/\\/g, "\\\\")
env = _.extend({}, process.env, {taskPath, userAgent: navigator.userAgent})
@childProcess = fork '--eval', [bootstrap], {env, silent: true}
@childProcess = ChildProcess.fork '--eval', [bootstrap], {env, silent: true}
@on "task:log", -> console.log(arguments...)
@on "task:warn", -> console.warn(arguments...)
@@ -102,10 +102,13 @@ class Task
@emit(event, args...) if @childProcess?
# Catch the errors that happened before task-bootstrap.
@childProcess.stdout.removeAllListeners()
@childProcess.stdout.on 'data', (data) -> console.log data.toString()
@childProcess.stderr.removeAllListeners()
@childProcess.stderr.on 'data', (data) -> console.error data.toString()
if @childProcess.stdout?
@childProcess.stdout.removeAllListeners()
@childProcess.stdout.on 'data', (data) -> console.log data.toString()
if @childProcess.stderr?
@childProcess.stderr.removeAllListeners()
@childProcess.stderr.on 'data', (data) -> console.error data.toString()
# Public: Starts the task.
#
@@ -153,8 +156,8 @@ class Task
return false unless @childProcess?
@childProcess.removeAllListeners()
@childProcess.stdout.removeAllListeners()
@childProcess.stderr.removeAllListeners()
@childProcess.stdout?.removeAllListeners()
@childProcess.stderr?.removeAllListeners()
@childProcess.kill()
@childProcess = null