From 1b2ff38aff6b92376c0ac485a7544f6dd7f43770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 3 Jul 2025 15:54:41 +0200 Subject: [PATCH 1/2] fix: serializing exception that didn't take an argument An exception that was instantiated without any argument could not be serilaized before. Now, I check if any args were supplied and set the value to an empty string if no args were passed. --- src/pydase/utils/serialization/serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydase/utils/serialization/serializer.py b/src/pydase/utils/serialization/serializer.py index 046c6c5..4685c06 100644 --- a/src/pydase/utils/serialization/serializer.py +++ b/src/pydase/utils/serialization/serializer.py @@ -158,7 +158,7 @@ class Serializer: "doc": None, "readonly": True, "type": "Exception", - "value": obj.args[0], + "value": obj.args[0] if len(obj.args) > 0 else "", "name": obj.__class__.__name__, } From 4cd36b4a2b0f31d676d5db0ef5cc5939dd384f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 3 Jul 2025 15:55:41 +0200 Subject: [PATCH 2/2] tests: adds test for exception serialization --- tests/utils/serialization/test_serializer.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/utils/serialization/test_serializer.py b/tests/utils/serialization/test_serializer.py index f0d8b53..97ed228 100644 --- a/tests/utils/serialization/test_serializer.py +++ b/tests/utils/serialization/test_serializer.py @@ -1225,3 +1225,22 @@ def test_add_prefix_to_full_access_path( serialized_obj: SerializedObject, prefix: str, expected: SerializedObject ) -> None: assert add_prefix_to_full_access_path(serialized_obj, prefix) == expected + + +def test_serialize_exception() -> None: + assert dump(Exception()) == { + "doc": None, + "full_access_path": "", + "name": "Exception", + "readonly": True, + "type": "Exception", + "value": "", + } + assert dump(Exception("Exception message")) == { + "doc": None, + "full_access_path": "", + "name": "Exception", + "readonly": True, + "type": "Exception", + "value": "Exception message", + }