Skip to content

Commit

Permalink
Extract error handling helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsawicki committed Apr 29, 2015
1 parent 213e6fd commit a67d961
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/buffered-process.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit a67d961

Please sign in to comment.