flatpak / libportal

libportal - Flatpak portal library
https://libportal.org
GNU Lesser General Public License v3.0
82 stars 40 forks source link

Report error instead of aborting when g_bus_get_sync fails #118

Closed marler8997 closed 1 year ago

marler8997 commented 1 year ago

In xdp_portal_init, the g_bus_get_sync can fail if a system has not properly set up DBUS. Instead of aborting, it would be nice if there was a way for the application to detect/handle this error, for example, reporting to the user that DBUS may not have been configured/setup properly.

It seems the reason for calling "abort" here could be because the Glib "init" hook doesn't provide a way to report an error? Maybe we'd have to add a function to check for errors on an XdpPortal object after it has been initialized?

TingPing commented 1 year ago

the Glib "init" hook doesn't provide a way to report an error?

It does have a way: GInitable.

My assumption is just that it was a shortcut.

All of libportal is going to fail without DBus. So every API needs to handle a no-dbus situation and error. This would be a tedious thing to do.

That said I really don't like the abort() here. It is bad form for any library.

TingPing commented 1 year ago

I guess we don't really need to make every API handle the situation.

Just implement GInitable, maybe add a new constructor with a GError and document that applications should use that and handle the failure.