[gnome-software/1612-revisit-error-display] gs-shell: Show detailed error message in a dialog
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1612-revisit-error-display] gs-shell: Show detailed error message in a dialog
- Date: Tue, 23 Aug 2022 12:19:10 +0000 (UTC)
commit e5e4779d514362a2f6273ea332f7ea2ec38f4620
Author: Milan Crha <mcrha redhat com>
Date: Tue Aug 23 14:16:46 2022 +0200
gs-shell: Show detailed error message in a dialog
Rather than in the notification bubble. It also allows to show
the complete message, not a cut message text.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1612
src/gs-shell.c | 105 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 55 insertions(+), 50 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index cd74178fb..90db3b4a3 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -74,6 +74,7 @@ struct _GsShell
GQueue *back_entry_stack;
GPtrArray *modal_dialogs;
gchar *events_info_uri;
+ gchar *events_more_info;
AdwLeaflet *main_leaflet;
AdwLeaflet *details_leaflet;
AdwViewStack *stack_loading;
@@ -736,6 +737,15 @@ static void
gs_shell_plugin_events_more_info_cb (GtkWidget *widget, GsShell *shell)
{
g_autoptr(GError) error = NULL;
+
+ /* Prefer detailed error message against origin's help URL */
+ if (shell->events_more_info != NULL) {
+ gs_utils_show_error_dialog_simple (GTK_WINDOW (shell),
+ gtk_label_get_text (GTK_LABEL (shell->label_events)),
+ shell->events_more_info);
+ return;
+ }
+
if (!g_app_info_launch_default_for_uri (shell->events_info_uri, NULL, &error)) {
g_warning ("failed to launch URI %s: %s",
shell->events_info_uri, error->message);
@@ -1221,42 +1231,21 @@ gs_shell_get_title_from_app (GsApp *app)
return g_strdup_printf (_("“%s”"), gs_app_get_id (app));
}
-static gchar *
-get_first_lines (const gchar *str)
-{
- const gchar *end = str;
- /* Some errors can have an "introduction", thus pick few initial lines, not only the first. */
- for (guint lines = 0; end != NULL && lines < 7; lines++) {
- end = strchr (end, '\n');
- if (end != NULL)
- end++;
- }
- if (end != NULL) {
- g_autofree gchar *tmp = g_strndup (str, end - str);
- /* Translators: The '%s' is replaced with an error message, which had been shortened.
- The dots at the end are there to highlight that to the user. */
- return g_strdup_printf (_("%s…"), tmp);
- }
- return g_strdup (str);
-}
-
-static void
-gs_shell_append_detailed_error (GsShell *shell, GString *str, const GError *error)
-{
- g_autofree gchar *text = get_first_lines (error->message);
- if (text != NULL) {
- g_autofree gchar *escaped = g_markup_escape_text (text, -1);
- g_string_append_printf (str, ":\n%s", escaped);
- }
-}
-
static gboolean
gs_shell_handle_events_more_info (GsShell *self,
- GsApp *origin)
+ GsApp *origin,
+ const gchar *more_info)
{
const gchar *uri;
g_clear_pointer (&self->events_info_uri, g_free);
+ g_clear_pointer (&self->events_more_info, g_free);
+
+ /* Prefer detailed error message against origin's help URL */
+ if (more_info != NULL && *more_info != '\0') {
+ self->events_more_info = g_strdup (more_info);
+ return TRUE;
+ }
if (origin == NULL)
return FALSE;
@@ -1276,6 +1265,7 @@ gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
GsPluginAction action = gs_plugin_event_get_action (event);
g_autofree gchar *str_origin = NULL;
g_autoptr(GString) str = g_string_new (NULL);
@@ -1305,7 +1295,7 @@ gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification */
g_string_append (str, _("Unable to download updates"));
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
} else if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NO_NETWORK)) {
/* TRANSLATORS: failure text for the in-app notification */
g_string_append (str, _("Unable to download updates: "
@@ -1348,13 +1338,13 @@ gs_shell_show_event_refresh (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification */
g_string_append (str, _("Unable to get list of updates"));
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1369,6 +1359,7 @@ gs_shell_show_event_install (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autofree gchar *str_app = NULL;
g_autofree gchar *str_origin = NULL;
g_autoptr(GString) str = g_string_new (NULL);
@@ -1391,7 +1382,7 @@ gs_shell_show_event_install (GsShell *shell, GsPluginEvent *event)
"as download failed"),
str_app);
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
} else if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED)) {
if (origin != NULL) {
str_origin = gs_shell_get_title_from_origin (origin);
@@ -1461,13 +1452,13 @@ gs_shell_show_event_install (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification,
* where the %s is the application name (e.g. "GIMP") */
g_string_append_printf (str, _("Unable to install %s"), str_app);
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1482,6 +1473,7 @@ gs_shell_show_event_update (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autofree gchar *str_app = NULL;
g_autofree gchar *str_origin = NULL;
g_autoptr(GString) str = g_string_new (NULL);
@@ -1518,7 +1510,7 @@ gs_shell_show_event_update (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification */
g_string_append_printf (str, _("Unable to install updates as download failed"));
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
} else if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NO_NETWORK)) {
/* TRANSLATORS: failure text for the in-app notification */
g_string_append (str, _("Unable to update: "
@@ -1621,13 +1613,13 @@ gs_shell_show_event_update (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification */
g_string_append_printf (str, _("Unable to install updates"));
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1642,6 +1634,7 @@ gs_shell_show_event_upgrade (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
g_autofree gchar *str_app = NULL;
g_autofree gchar *str_origin = NULL;
@@ -1663,7 +1656,7 @@ gs_shell_show_event_upgrade (GsShell *shell, GsPluginEvent *event)
"as download failed"),
str_app);
}
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
} else if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NO_NETWORK)) {
/* TRANSLATORS: failure text for the in-app notification,
* where the %s is the distro name (e.g. "Fedora 25") */
@@ -1716,13 +1709,13 @@ gs_shell_show_event_upgrade (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification,
* where the %s is the distro name (e.g. "Fedora 25") */
g_string_append_printf (str, _("Unable to upgrade to %s"), str_app);
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1737,6 +1730,7 @@ gs_shell_show_event_remove (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
g_autofree gchar *str_app = NULL;
@@ -1780,13 +1774,13 @@ gs_shell_show_event_remove (GsShell *shell, GsPluginEvent *event)
/* TRANSLATORS: failure text for the in-app notification,
* where the %s is the application name (e.g. "GIMP") */
g_string_append_printf (str, _("Unable to remove %s"), str_app);
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1801,6 +1795,7 @@ gs_shell_show_event_launch (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
g_autofree gchar *str_app = NULL;
g_autofree gchar *str_origin = NULL;
@@ -1831,13 +1826,13 @@ gs_shell_show_event_launch (GsShell *shell, GsPluginEvent *event)
return FALSE;
/* TRANSLATORS: we failed to get a proper error code */
g_string_append (str, _("Sorry, something went wrong"));
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -1850,6 +1845,7 @@ gs_shell_show_event_file_to_app (GsShell *shell, GsPluginEvent *event)
{
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED)) {
@@ -1872,12 +1868,15 @@ gs_shell_show_event_file_to_app (GsShell *shell, GsPluginEvent *event)
return FALSE;
/* TRANSLATORS: we failed to get a proper error code */
g_string_append (str, _("Sorry, something went wrong"));
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
+ if (gs_shell_handle_events_more_info (shell, NULL, more_info))
+ buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
+
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
return TRUE;
@@ -1888,6 +1887,7 @@ gs_shell_show_event_url_to_app (GsShell *shell, GsPluginEvent *event)
{
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED)) {
@@ -1910,12 +1910,15 @@ gs_shell_show_event_url_to_app (GsShell *shell, GsPluginEvent *event)
return FALSE;
/* TRANSLATORS: we failed to get a proper error code */
g_string_append (str, _("Sorry, something went wrong"));
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
+ if (gs_shell_handle_events_more_info (shell, NULL, more_info))
+ buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
+
/* show in-app notification */
gs_shell_show_event_app_notify (shell, str->str, buttons);
return TRUE;
@@ -1927,6 +1930,7 @@ gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
GsApp *origin = gs_plugin_event_get_origin (event);
GsShellEventButtons buttons = GS_SHELL_EVENT_BUTTON_NONE;
const GError *error = gs_plugin_event_get_error (event);
+ const gchar *more_info = NULL;
g_autoptr(GString) str = g_string_new (NULL);
g_autofree gchar *str_origin = NULL;
@@ -1963,13 +1967,13 @@ gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
return FALSE;
/* TRANSLATORS: we failed to get a proper error code */
g_string_append (str, _("Sorry, something went wrong"));
- gs_shell_append_detailed_error (shell, str, error);
+ more_info = error->message;
}
if (str->len == 0)
return FALSE;
- if (gs_shell_handle_events_more_info (shell, origin))
+ if (gs_shell_handle_events_more_info (shell, origin, more_info))
buttons |= GS_SHELL_EVENT_BUTTON_MORE_INFO;
/* show in-app notification */
@@ -2468,6 +2472,7 @@ gs_shell_dispose (GObject *object)
g_clear_object (&shell->header_end_widget);
g_clear_object (&shell->page);
g_clear_pointer (&shell->events_info_uri, g_free);
+ g_clear_pointer (&shell->events_more_info, g_free);
g_clear_pointer (&shell->modal_dialogs, g_ptr_array_unref);
g_clear_object (&shell->settings);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]