Skip to content

Async method calls do not show/print exceptions #97

@arkq

Description

@arkq

If the exception occur in a method callback, the exception is not shown:

import asyncio
import sdbus

class Test(sdbus.DbusInterfaceCommonAsync, interface_name="org.test"):
    @sdbus.dbus_method_async(result_signature="u")
    async def open(self) -> int:
        print("Open call")
        raise ValueError("Nooo")

test = Test()

async def startup() -> None:
    await sdbus.request_default_bus_name_async('org.example.test')
    test.export_to_dbus("/")

loop = asyncio.new_event_loop()
loop.run_until_complete(startup())
loop.run_until_complete(asyncio.sleep(10))
print("Done")
$ ./test.py
Open call
Done
$ gdbus call --session --dest org.example.test --object-path / --method org.test.Open
Error: GDBus.Error:org.freedesktop.DBus.Error.Failed:

It is visible on the client side that something was wrong DBus.Error.Failed, but it's hard to tell what was wrong. It would be nice to have a traceback printed in case of an exception in a D-Bus API handler (method or property). However, I'm not sure whether that is intentional or a bug?

As a workaround I can wrap method/property code in a try/except block, but I think that it would be nicer to have a traceback in case of non-DBus exception. If someone would like to return an error from a method/property, a dedicated DBus exception should be used. What do you think? Otherwise it's really, reaaaaalllyyy hard to debug issues (e.g. a simple typo) in a program based on sdbus library.

If not, the returned D-Bus error should at least have the ValueError's message included.

Setup

sdbus was installed via PIP:

$ pip freeze |grep sdbus
sdbus==0.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions