From e5d0f32d8c20c02b17fa46ef1a0b88c9bb9124a6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 8 May 2024 19:51:29 -0400 Subject: [PATCH] css: Improve error reporting for variables Emit errors for all the variables that were being expanded if an error occurs while parsing a property value at compute time. Include the variables that are being expanded in the error message. --- gtk/gtkcssreferencevalue.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/gtk/gtkcssreferencevalue.c b/gtk/gtkcssreferencevalue.c index 01ec4015b0..cff58edeb2 100644 --- a/gtk/gtkcssreferencevalue.c +++ b/gtk/gtkcssreferencevalue.c @@ -209,15 +209,39 @@ parser_error (GtkCssParser *parser, gpointer user_data) { GtkStyleProvider *provider = user_data; - GtkCssSection *section; + GError *new_error = NULL; + GtkCssVariableValue **vars; + char **names; + gsize n_vars; - section = gtk_css_section_new (gtk_css_parser_get_file (parser), - start, - end); + gtk_css_parser_get_expanding_variables (parser, &vars, &names, &n_vars); - gtk_style_provider_emit_error (provider, section, (GError *) error); + if (n_vars > 0) + { + for (int i = 0; i < n_vars; i++) + { + if (names[i + 1]) + g_set_error (&new_error, + GTK_CSS_PARSER_ERROR, GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE, + "While expanding %s: %s", names[i + 1], error->message); + else + g_set_error_literal (&new_error, + GTK_CSS_PARSER_ERROR, GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE, + error->message); + gtk_style_provider_emit_error (provider, vars[i]->section, new_error); + g_clear_error (&new_error); + } - gtk_css_section_unref (section); + for (int i = 0; i < n_vars; i++) + { + if (vars[i]) + gtk_css_variable_value_unref (vars[i]); + g_free (names[i]); + } + + g_free (vars); + g_free (names); + } } static GtkCssValue *