Error handling and Value Mapping #71
Replies: 1 comment
-
Hello @dragomirecky Knowing about errorsI have a plan on adding different loggers from the standard library. For example, the errors that D-Bus requests produce can be logged to the Translating Python Errors
I will need to look in to this. It probably can't be a mapping but a sequence of elements appended to the exception's Translating Python ValuesEnums should already work. On the server simply return the enum member and it will be appended to the message as int. This is because enum member are the subclass of its values so class MyInterface(DbusInterfaceCommonAsync, interface_name=...):
@dbus_property_mapped_async(property_signature="i")
def my_property(self) -> int:
return SomeEnum.VALUE_B The only issue is that on client you will need to manually convert SomeEnum(await my_interface.my_property) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am still in a process of integrating this library into one of my new projects and I have reached a few limitations of the API. There might be a common solution to all of them, so I will not spread them in multiple discussions :)
Knowing about errors
The first β and the smallest one β is not knowing when some error happens in a method/property handler. It is minor, but if I implement some Dbus service, a common need is to print errors that happen within that service to stderr, for example. But it seems to me that is not possible with the current implementation. As there is no way to "intercept the error and do something about it".
My current solution is super simple β I just added logging to the library (dragomirecky@93929ae) as that solves the primary issue for me. But that is not a general solution I believe.
Translating Python Errors
I need to translate Python exceptions to Dbus errors and on the other side back to Python exceptions.
So for example, with code like this
I would like to be able to choose how the exception is going to be translated to DBus error message.
my.domain.Error
{ "message": "something went wrong", "code": 4, "reason": "it broke" }
Second feature regarding this is that when the error gets serialized like above, I would like to be able to make the interface such that it automatically translates the error back to the native
MyDomainError
.So that when user calls
Translating Python Values
Last thing β relevant to the other two β is missing a possibility to map object to DBus values and back. I believe this is a common need for properties. To solve this temporarily I have created a custom decorator for this:
I believe all those three issues can be solved with a single feature β something like the middleware pattern which is common in http servers. Ideally composable using decorators.
I am aware it is not trivial to do this nicely composable in a fully type-safe manner. But I think if made right, it would allow whole set of new uses while keeping the library nicely clean and simple.
What are your thoughts? I would be happy to invest some time into this if we find a way forward on this
Beta Was this translation helpful? Give feedback.
All reactions