From f8de1644135ede7f2f472c82bc899e0673de9583 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 7 Oct 2020 16:08:09 +0200 Subject: [PATCH] api: properly encode exception type When using `str(type(exception))` this ends up to be something like `` for a `ValueError` exception. Get the vanilla name of the exception type via `type(exception).__name__`. Add a test to ensure that we encode this properly. --- osbuild/api.py | 2 +- test/mod/test_api.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/osbuild/api.py b/osbuild/api.py index 2c65a0ff..baa985ae 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -213,7 +213,7 @@ def exception(e, path="/run/osbuild/api/osbuild"): msg = { "method": "exception", "exception": { - "type": str(type(e)), + "type": type(e).__name__, "value": str(e), "traceback": str(e.__traceback__) } diff --git a/test/mod/test_api.py b/test/mod/test_api.py index ee42a80a..c244b4b0 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -103,6 +103,7 @@ class TestAPI(unittest.TestCase): for field in ("type", "value", "traceback"): self.assertIn(field, e, f"Exception needs '{field}'") self.assertEqual(e["value"], "osbuild test exception") + self.assertEqual(e["type"], "ValueError") def test_metadata(self): # Check that `api.metadata` leads to `API.metadata` being