From 5564d9eb4624c791554d81b8a6ecaf0f5326259d Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 19 Oct 2022 22:27:07 +0100 Subject: [PATCH] Catch dbus exceptions in async callbacks on completion (GTK client) (#3997) GLIBMM will catch them for us, but in two cases print a warning instead of suppressing, and in one other case still print a warning (as well as we do) but without context. --- gtk/Notify.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/gtk/Notify.cc b/gtk/Notify.cc index 1c320d643..e645c2035 100644 --- a/gtk/Notify.cc +++ b/gtk/Notify.cc @@ -50,7 +50,16 @@ Glib::VariantContainerBase make_variant_tuple(Ts&&... args) void get_capabilities_callback(Glib::RefPtr& res) { - auto result = proxy->call_finish(res); + auto result = Glib::VariantContainerBase(); + + try + { + result = proxy->call_finish(res); + } + catch (Glib::Error const&) + { + return; + } if (!result || result.get_n_children() != 1 || !result.get_child(0).is_of_type(StringListVariantType::variant_type())) { @@ -121,11 +130,20 @@ void g_signal_callback( void dbus_proxy_ready_callback(Glib::RefPtr& res) { - proxy = Gio::DBus::Proxy::create_for_bus_finish(res); - - if (proxy == nullptr) + try { - g_warning("%s", fmt::format(_("Couldn't create proxy for '{bus}'"), fmt::arg("bus", NotificationsDbusName)).c_str()); + proxy = Gio::DBus::Proxy::create_for_bus_finish(res); + } + catch (Glib::Error const& e) + { + g_warning( + "%s", + fmt::format( + _("Couldn't create proxy for '{bus}': {error} ({error_code})"), + fmt::arg("bus", NotificationsDbusName), + fmt::arg("error", TR_GLIB_EXCEPTION_WHAT(e)), + fmt::arg("error_code", e.code())) + .c_str()); return; } @@ -152,7 +170,16 @@ namespace void notify_callback(Glib::RefPtr& res, TrNotification const& n) { - auto result = proxy->call_finish(res); + auto result = Glib::VariantContainerBase(); + + try + { + result = proxy->call_finish(res); + } + catch (Glib::Error const&) + { + return; + } if (!result || result.get_n_children() != 1 || !result.get_child(0).is_of_type(UInt32VariantType::variant_type())) {