Extract error handling helper

This commit is contained in:
Kevin Sawicki 2015-04-28 11:46:04 -07:00
parent 213e6fd611
commit a67d9615a8

View File

@ -102,17 +102,7 @@ class BufferedProcess
processExited = true
triggerExitCallback()
@process.on 'error', (error) =>
handled = false
handle = -> handled = true
@emitter.emit 'will-throw-error', {error, handle}
if error.code is 'ENOENT' and error.syscall.indexOf('spawn') is 0
error = new Error("Failed to spawn command `#{command}`. Make sure `#{command}` is installed and on your PATH", error.path)
error.name = 'BufferedProcessError'
throw error unless handled
@process.on 'error', (error) => @handleError(error)
###
Section: Event Subscription
@ -222,3 +212,15 @@ class BufferedProcess
@killProcess()
undefined
handleError: (error) ->
handled = false
handle = -> handled = true
@emitter.emit 'will-throw-error', {error, handle}
if error.code is 'ENOENT' and error.syscall.indexOf('spawn') is 0
error = new Error("Failed to spawn command `#{command}`. Make sure `#{command}` is installed and on your PATH", error.path)
error.name = 'BufferedProcessError'
throw error unless handled