From 237eb47d73079f2dcc54086ad75b6b17a58eca6b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 19 May 2021 14:20:43 +0200 Subject: 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. --- mdbp/ssh.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'mdbp') 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() -- cgit v1.2.3