[gnome-software/wip/mcrha/too-short-error-message] gs-shell: Show more than one line of an error message



commit f6bd410bf856772acbeac459e14b81a105989367
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 3 14:54:12 2021 +0100

    gs-shell: Show more than one line of an error message
    
    There was added a limit of how many lines of an error message to show
    to avoid too long messages, but showing only one line can be rather useless,
    thus bump the limit to the first 7 lines.

 src/gs-shell.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 9e2cde8c8..59485aa29 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -1184,23 +1184,25 @@ gs_shell_get_title_from_app (GsApp *app)
 }
 
 static gchar *
-get_first_line (const gchar *str)
+get_first_lines (const gchar *str)
 {
-       g_auto(GStrv) lines = NULL;
-
-       lines = g_strsplit (str, "\n", 2);
-       if (lines != NULL && g_strv_length (lines) != 0)
-               return g_strdup (lines[0]);
-
-       return NULL;
+       const gchar *end = str;
+       for (guint lines = 0; end != NULL && lines < 7; lines++) {
+               end = strchr (end, '\n');
+               if (end != NULL)
+                       end++;
+       }
+       if (end != NULL)
+               return g_strdup_printf ("%.*s…", (gint) (end - str), str);
+       return g_strdup (str);
 }
 
 static void
 gs_shell_append_detailed_error (GsShell *shell, GString *str, const GError *error)
 {
-       g_autofree gchar *first_line = get_first_line (error->message);
-       if (first_line != NULL) {
-               g_autofree gchar *escaped = g_markup_escape_text (first_line, -1);
+       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);
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]