I am running a command with Twisted's ProcessProtocol.
I am using the documentation scaffold and I have several events like inConnectionLost, connectionMade, etc
But when the process finish this event is triggered:
def processExited(self, reason):
print 'processExited, status %d' % (reason.value.exitCode,)
if reason.value.exitCode == 0:
print 'SUCCESS!!!'
else:
print 'ERROR!!!'
raise RuntimeError, 'some custom error message'
As you can see I am trying to raise the error to catch it in an upper level. I am wrapping the command call with a deferred like this:
def success_pipeline(success):
log.debug('The pipeline has finished correctly.')
def failure_pipeline(error, command):
log.debug('The pipeline failed...')
command = CommandProtocol()
reactor.spawnProcess(command, application_bin, command_arguments, {})
d = Deferred()
d.addCallback(success_pipeline)
d.addErrback(failure_pipeline, command)
return d
But, although the command failed (I manually mistyped the arguments) it's always going into the success callback. The reason.value.exitCode is 1 so in bash it's confirmed it failed.
So how can I catch an errback to custom handle the failure?