g_app_info_launch_default_for_uri does not set error object when there is an error
In glib version 1.2.10 on fedora 33, the call to g_app_info_launch_default_for_uri()
with a faulty uri string, I found that the function returns FALSE
correctly but that the error object is not set. So there is no way to know what went wrong.
Checking the source code (of glib 2.60.7), partly shown below, I see that it is possible, after an initial check for app_info
, to see if it needs to be created as a GFile
, that when the app_info
is still not initialized, the error object stays empty. That is for all non-unix systems or when glib_should_use_portal()
returns FALSE
.
uri_scheme = g_uri_parse_scheme (uri);
if (uri_scheme && uri_scheme[0] != '\0')
app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
g_free (uri_scheme);
if (!app_info)
{
GFile *file;
file = g_file_new_for_uri (uri);
app_info = g_file_query_default_handler (file, NULL, error);
g_object_unref (file);
}
if (app_info)
{
GList l;
l.data = (char *)uri;
l.next = l.prev = NULL;
res = g_app_info_launch_uris (app_info, &l, launch_context, error);
g_object_unref (app_info);
}
#ifdef G_OS_UNIX
if (!res && glib_should_use_portal ())
{
const char *parent_window = NULL;
/* Reset any error previously set by launch_default_for_uri */
g_clear_error (error);
if (launch_context && launch_context->priv->envp)
parent_window = g_environ_getenv (launch_context->priv->envp, "PARENT_WINDOW_ID");
return g_openuri_portal_open_uri (uri, parent_window, error);
}
#endif