mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 09:48:56 +00:00
specific exception for failing subprocess
This commit is contained in:
parent
c823ff1195
commit
4ece4e9dce
@ -190,8 +190,5 @@ def test_reject_storage_server(reactor, request, storage_nodes, temp_dir, introd
|
||||
stdin="some content" * 200,
|
||||
)
|
||||
assert False, "Should get a failure"
|
||||
except Exception as e:
|
||||
# depending on the full output being in the error-message
|
||||
# here; see util.py
|
||||
assert 'UploadUnhappinessError' in str(e)
|
||||
print("found expected UploadUnhappinessError")
|
||||
except util.ProcessFailed as e:
|
||||
assert 'UploadUnhappinessError' in e.output.getvalue()
|
||||
|
@ -42,8 +42,8 @@ def test_upload_immutable(reactor, temp_dir, introducer_furl, flog_gatherer, sto
|
||||
try:
|
||||
yield proto.done
|
||||
assert False, "should raise exception"
|
||||
except Exception as e:
|
||||
assert "UploadUnhappinessError" in str(e)
|
||||
except util.ProcessFailed as e:
|
||||
assert "UploadUnhappinessError" in e.output.getvalue()
|
||||
|
||||
output = proto.output.getvalue()
|
||||
assert "shares could be placed on only" in output
|
||||
|
@ -32,6 +32,20 @@ class _ProcessExitedProtocol(ProcessProtocol):
|
||||
self.done.callback(None)
|
||||
|
||||
|
||||
class ProcessFailed(Exception):
|
||||
"""
|
||||
A subprocess has failed.
|
||||
|
||||
:ivar ProcessTerminated reason: the original reason from .processExited
|
||||
|
||||
:ivar StringIO output: all stdout and stderr collected to this point.
|
||||
"""
|
||||
|
||||
def __init__(self, reason, output):
|
||||
self.reason = reason
|
||||
self.output = output
|
||||
|
||||
|
||||
class _CollectOutputProtocol(ProcessProtocol):
|
||||
"""
|
||||
Internal helper. Collects all output (stdout + stderr) into
|
||||
@ -54,13 +68,7 @@ class _CollectOutputProtocol(ProcessProtocol):
|
||||
|
||||
def processExited(self, reason):
|
||||
if not isinstance(reason.value, ProcessDone):
|
||||
#self.done.errback(reason)
|
||||
self.done.errback(RuntimeError(
|
||||
"Process failed: {}\nOutput:\n{}".format(
|
||||
reason,
|
||||
self.output.getvalue(),
|
||||
)
|
||||
))
|
||||
self.done.errback(ProcessFailed(reason, self.output))
|
||||
|
||||
def outReceived(self, data):
|
||||
self.output.write(data)
|
||||
|
Loading…
Reference in New Issue
Block a user