From 02ad4e3810ff14058d9ccc474f4dd5b5e6de06ef Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Sat, 4 Jan 2020 02:03:52 +0200 Subject: [PATCH] sources: fail gracefully when a source returns invalid JSON Include the actual output of the source to help debugging. --- osbuild/sources.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osbuild/sources.py b/osbuild/sources.py index 53656a29..85d1c64f 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -26,7 +26,10 @@ class SourcesServer: encoding="utf-8", check=False) - return json.loads(r.stdout) + try: + return json.loads(r.stdout) + except ValueError: + return {"error": f"source returned malformed json: {r.stdout}"} def _dispatch(self, sock): msg, addr = sock.recvfrom(8182)