summaryrefslogtreecommitdiff
path: root/mdbp
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-05-19 14:20:43 +0200
committerHelmut Grohne <helmut@subdivi.de>2021-05-19 14:20:43 +0200
commit237eb47d73079f2dcc54086ad75b6b17a58eca6b (patch)
treed57e0f1ab8eb3d855273690bb7f4e99507ade97a /mdbp
parent1b5a9de35ae10f46de19474dea4065a6c0fc3a9e (diff)
downloadmdbp-237eb47d73079f2dcc54086ad75b6b17a58eca6b.tar.gz
ssh: improve handling of failed builds
When the wrapped backend fails, streamapi does not produce an artifact tar on stdout. When this goes missing, we'll see a traceback. Hide that traceback and adapt the exit code if necessary.
Diffstat (limited to 'mdbp')
-rw-r--r--mdbp/ssh.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/mdbp/ssh.py b/mdbp/ssh.py
index 8af6bde..50b7d25 100644
--- a/mdbp/ssh.py
+++ b/mdbp/ssh.py
@@ -3,6 +3,7 @@
"""mdbp backend wrapper via ssh"""
import argparse
+import contextlib
import io
import json
import pathlib
@@ -61,13 +62,22 @@ def main() -> None:
assert proc.stdin is not None
produce_request_tar(build, proc.stdin)
proc.stdin.close()
- with tarfile.open(fileobj=proc.stdout, mode="r|") as outtar:
- for member in outtar:
- if "/" in member.name or not member.isfile():
- raise ValueError("expected flat tar as output")
- outtar.extract(member, build["output"]["directory"],
- set_attrs=False)
- sys.exit(proc.wait())
+ exitcode = 0
+ with contextlib.ExitStack() as stack:
+ try:
+ outtar = stack.enter_context(tarfile.open(fileobj=proc.stdout,
+ mode="r|"))
+ except tarfile.ReadError as err:
+ if str(err) != "empty file":
+ raise
+ exitcode = 1
+ else:
+ for member in outtar:
+ if "/" in member.name or not member.isfile():
+ raise ValueError("expected flat tar as output")
+ outtar.extract(member, build["output"]["directory"],
+ set_attrs=False)
+ sys.exit(proc.wait() or exitcode)
if __name__ == "__main__":
main()