mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-10 22:43:52 +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,
|
stdin="some content" * 200,
|
||||||
)
|
)
|
||||||
assert False, "Should get a failure"
|
assert False, "Should get a failure"
|
||||||
except Exception as e:
|
except util.ProcessFailed as e:
|
||||||
# depending on the full output being in the error-message
|
assert 'UploadUnhappinessError' in e.output.getvalue()
|
||||||
# here; see util.py
|
|
||||||
assert 'UploadUnhappinessError' in str(e)
|
|
||||||
print("found expected UploadUnhappinessError")
|
|
||||||
|
@ -42,8 +42,8 @@ def test_upload_immutable(reactor, temp_dir, introducer_furl, flog_gatherer, sto
|
|||||||
try:
|
try:
|
||||||
yield proto.done
|
yield proto.done
|
||||||
assert False, "should raise exception"
|
assert False, "should raise exception"
|
||||||
except Exception as e:
|
except util.ProcessFailed as e:
|
||||||
assert "UploadUnhappinessError" in str(e)
|
assert "UploadUnhappinessError" in e.output.getvalue()
|
||||||
|
|
||||||
output = proto.output.getvalue()
|
output = proto.output.getvalue()
|
||||||
assert "shares could be placed on only" in output
|
assert "shares could be placed on only" in output
|
||||||
|
@ -32,6 +32,20 @@ class _ProcessExitedProtocol(ProcessProtocol):
|
|||||||
self.done.callback(None)
|
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):
|
class _CollectOutputProtocol(ProcessProtocol):
|
||||||
"""
|
"""
|
||||||
Internal helper. Collects all output (stdout + stderr) into
|
Internal helper. Collects all output (stdout + stderr) into
|
||||||
@ -54,13 +68,7 @@ class _CollectOutputProtocol(ProcessProtocol):
|
|||||||
|
|
||||||
def processExited(self, reason):
|
def processExited(self, reason):
|
||||||
if not isinstance(reason.value, ProcessDone):
|
if not isinstance(reason.value, ProcessDone):
|
||||||
#self.done.errback(reason)
|
self.done.errback(ProcessFailed(reason, self.output))
|
||||||
self.done.errback(RuntimeError(
|
|
||||||
"Process failed: {}\nOutput:\n{}".format(
|
|
||||||
reason,
|
|
||||||
self.output.getvalue(),
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
def outReceived(self, data):
|
def outReceived(self, data):
|
||||||
self.output.write(data)
|
self.output.write(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user