diff --git a/osbuild/api.py b/osbuild/api.py index baa985ae..dca69d93 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -210,12 +210,15 @@ def exception(e, path="/run/osbuild/api/osbuild"): """Send exception to osbuild""" traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) with jsoncomm.Socket.new_client(path) as client: + with io.StringIO() as out: + traceback.print_tb(e.__traceback__, file=out) + stacktrace = out.getvalue() msg = { "method": "exception", "exception": { "type": type(e).__name__, "value": str(e), - "traceback": str(e.__traceback__) + "traceback": stacktrace } } client.send(msg) diff --git a/test/mod/test_api.py b/test/mod/test_api.py index 986aa17f..7ffee3c3 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -103,6 +103,7 @@ class TestAPI(unittest.TestCase): self.assertIn(field, e, f"Exception needs '{field}'") self.assertEqual(e["value"], "osbuild test exception") self.assertEqual(e["type"], "ValueError") + self.assertIn("exception", e["traceback"]) def test_metadata(self): # Check that `api.metadata` leads to `API.metadata` being