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.
This commit is contained in:
Mike Gelfand 2022-10-19 22:27:07 +01:00 committed by GitHub
parent 3a8dc9d203
commit 5564d9eb46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 6 deletions

View File

@ -50,7 +50,16 @@ Glib::VariantContainerBase make_variant_tuple(Ts&&... args)
void get_capabilities_callback(Glib::RefPtr<Gio::AsyncResult>& 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<Gio::AsyncResult>& 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<Gio::AsyncResult>& 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()))
{