From c5db26596ff4c4d8f07ec0db01f70a8fc0d2aba7 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 7 Sep 2020 20:35:32 +0200 Subject: [PATCH] plugin/builder: nicer errors on compose fail When creating the compose requests fails, catch it and transform it into a koji.GenericError, which will avoid showing the full backtrace in the UI. --- plugins/builder/osbuild.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/builder/osbuild.py b/plugins/builder/osbuild.py index f5ae2b6..1df44b9 100644 --- a/plugins/builder/osbuild.py +++ b/plugins/builder/osbuild.py @@ -135,18 +135,24 @@ class Client: def __init__(self, url): self.url = url - def compose_create(self, nvr: NVR, distro: str, images: List[ImageRequest], koji: str): + def compose_create(self, nvr: NVR, distro: str, images: List[ImageRequest], kojiurl: str): url = urllib.parse.urljoin(self.url, f"/compose") req = urllib.request.Request(url) - cro = ComposeRequest(nvr, distro, images, koji) + cro = ComposeRequest(nvr, distro, images, kojiurl) dat = json.dumps(cro.as_dict()) raw = dat.encode('utf-8') req = urllib.request.Request(url, raw) req.add_header('Content-Type', 'application/json') req.add_header('Content-Length', len(raw)) - with urllib.request.urlopen(req, raw) as res: - payload = res.read().decode('utf-8') + try: + with urllib.request.urlopen(req, raw) as res: + payload = res.read().decode('utf-8') + except urllib.error.HTTPError as e: + body = e.read().decode('utf-8').strip() + msg = f"Failed to create the compose request: {body}" + raise koji.GenericError(msg) from None + ps = json.loads(payload) compose_id, koji_build_id = ps["id"], ps["koji_build_id"] return compose_id, koji_build_id