Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc or examples don't include handling of dbus method errors #65

Open
pespin opened this issue Aug 25, 2017 · 3 comments
Open

Doc or examples don't include handling of dbus method errors #65

pespin opened this issue Aug 25, 2017 · 3 comments

Comments

@pespin
Copy link

pespin commented Aug 25, 2017

In Dbus methods can return errors instead of returning expected value. I could not find simple example or good documentation on how to handle them. A simple example showing how to handle common errors should be provided, as well as adding a paragraph in the documentation/tutorial.

For instance, from ofono https://git.kernel.org/pub/scm/network/ofono/ofono.git/tree/doc/network-api.txt:

		void Register()

			Attempts to register to the default network. The
			default network is normally selected by the settings
			from the SIM card.

			Possible Errors: [service].Error.InProgress
					 [service].Error.NotImplemented
					 [service].Error.Failed
					 [service].Error.AccessDenied

And I got this stack trace today:

    dbus_op.Register()
  File "/usr/local/lib/python3.4/dist-packages/pydbus/proxy_method.py", line 75, in __call__
    0, timeout_to_glib(timeout), None).unpack()
GLib.Error: g-io-error-quark: GDBus.Error:org.ofono.Error.InProgress: Operation already in progress (36)

For now I'll try to do something like this, but it's still not clear to me whether this is correct or not:

        try:
            netreg.Register()
        except org.ofono.Error.InProgress as e:
            self.log('Register already in progress', e)
@pespin
Copy link
Author

pespin commented Aug 25, 2017

For reference, I'm finally doing something like this now. Still not checked it's correct as I cannot reproduce the exception:

    try:
        method()
    except Exception as e:
        if isinstance(e, GLib.Error) and err_str in e.domain:
            return
        raise e

@Hegz
Copy link

Hegz commented Jun 30, 2020

I ended up with:

from gi.repository.GLib import GError

...

try:
  thing()
except GError as e:
  if 'dbus.Error.Name' in str(e.args):
    print('Deal with this error')
  else:
    raise e

still learning python, so not sure if that's right, but it is handling the exception.

@jlucier
Copy link

jlucier commented Jul 16, 2020

This is probably useful as reference: https://pygobject.readthedocs.io/en/latest/guide/api/error_handling.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants