aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-02-24 23:53:31 -0500
committerJohn Thacker <johnthacker@gmail.com>2023-03-06 12:17:02 +0000
commit53914b044780c3ebac42f465d7f54df27933d22e (patch)
tree802aa3472f3736ce32b6ec934870645664f969d5
parentc682f53222a7c9e4a9a554c5ad809612387e5cc5 (diff)
colors: Improve handling of errors
Pop up a dialog about bad coloring rules when reading the file (e.g., when first starting Wireshark), rather than waiting until you try to edit them. Have that dialog have details of the problem with the filter instead of a generic message. The report_warning code will consolidate multiple warnings into one if more than one filter has an error, rather than have lots of pop-ups. Since the dialog (or console message, in the unlikely event that somehow the colorfilters are read in a CLI tool) is called from the color filters code, get rid of the separate non-specific pop-up in ColoringRulesDialog and the special preference for having a bogus filter. Now, if the user has a bogus filter in the current profile's colorfilter, they'll get a useful pop-up warning at startup, when that filter is disabled. For filters imported / copied from other profiles through the coloring rules dialog, they'll get the same useful pop-up. For trying to enable a disabled coloring rules with an error, or inserting a *new* coloring rule with invalid filter expression (despite the editor's Red background warning about an invalid expression), there's already both the hint at the bottom of the screen and the OK button becomes disabled. (Maybe the hint could be larger or bold or something when there's an error.) Fix #14906. Fix #15034
-rw-r--r--epan/color_filters.c7
-rw-r--r--epan/prefs.h1
-rw-r--r--ui/qt/coloring_rules_dialog.cpp22
3 files changed, 2 insertions, 28 deletions
diff --git a/epan/color_filters.c b/epan/color_filters.c
index c9929fd8a9..809c70a35f 100644
--- a/epan/color_filters.c
+++ b/epan/color_filters.c
@@ -22,6 +22,7 @@
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
+#include <wsutil/report_message.h>
#include <wsutil/wslog.h>
#include <wsutil/ws_assert.h>
@@ -609,8 +610,6 @@ read_filters_file(const gchar *path, FILE *f, gpointer user_data, color_filter_a
name = (gchar *)g_malloc(name_len + 1);
filter_exp = (gchar *)g_malloc(filter_exp_len + 1);
- prefs.unknown_colorfilters = FALSE;
-
while (1) {
if (skip_end_of_line) {
@@ -704,10 +703,8 @@ read_filters_file(const gchar *path, FILE *f, gpointer user_data, color_filter_a
df_error_t *df_err = NULL;
if (!disabled && !dfilter_compile(filter_exp, &temp_dfilter, &df_err)) {
- ws_warning("Could not compile \"%s\" in colorfilters file \"%s\".\n%s",
- name, path, df_err->msg);
+ report_warning("Disabling color filter: Could not compile \"%s\" in colorfilters file \"%s\".\n%s", name, path, df_err->msg);
dfilter_error_free(df_err);
- prefs.unknown_colorfilters = TRUE;
/* skip_end_of_line = TRUE; */
disabled = TRUE;
diff --git a/epan/prefs.h b/epan/prefs.h
index 7a7b72348d..c771a25337 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -211,7 +211,6 @@ typedef struct _e_prefs {
gint gui_debounce_timer;
gchar *saved_at_version;
gboolean unknown_prefs; /* unknown or obsolete pref(s) */
- gboolean unknown_colorfilters; /* Warn when saving unknown or obsolete color filters. */
gboolean gui_qt_packet_list_separator;
gboolean gui_qt_packet_header_column_definition;
gboolean gui_qt_packet_list_hover_style; /* Enable/Disable mouse-over colorization */
diff --git a/ui/qt/coloring_rules_dialog.cpp b/ui/qt/coloring_rules_dialog.cpp
index d60b73c379..df178ec101 100644
--- a/ui/qt/coloring_rules_dialog.cpp
+++ b/ui/qt/coloring_rules_dialog.cpp
@@ -116,8 +116,6 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
ui->coloringRulesTreeView->setCurrentIndex(QModelIndex());
}
- checkUnknownColorfilters();
-
updateHint();
}
@@ -126,22 +124,6 @@ ColoringRulesDialog::~ColoringRulesDialog()
delete ui;
}
-void ColoringRulesDialog::checkUnknownColorfilters()
-{
- if (prefs.unknown_colorfilters) {
- QMessageBox *mb = new QMessageBox();
- mb->setText(tr("Your coloring rules file contains unknown rules"));
- mb->setInformativeText(tr("Wireshark doesn't recognize one or more of your coloring rules. "
- "They have been disabled."));
- mb->setStandardButtons(QMessageBox::Ok);
-
- mb->setWindowModality(Qt::ApplicationModal);
- mb->setAttribute(Qt::WA_DeleteOnClose);
- mb->show();
- prefs.unknown_colorfilters = FALSE;
- }
-}
-
void ColoringRulesDialog::copyFromProfile(QString filename)
{
QString err;
@@ -153,8 +135,6 @@ void ColoringRulesDialog::copyFromProfile(QString filename)
for (int i = 0; i < colorRuleModel_.columnCount(); i++) {
ui->coloringRulesTreeView->resizeColumnToContents(i);
}
-
- checkUnknownColorfilters();
}
void ColoringRulesDialog::showEvent(QShowEvent *)
@@ -440,8 +420,6 @@ void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button)
if (!colorRuleModel_.importColors(file_name, err)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err.toUtf8().constData());
}
-
- checkUnknownColorfilters();
}
} else if (button == export_button_) {
int num_items = static_cast<int>(ui->coloringRulesTreeView->selectionModel()->selectedIndexes().count()) / colorRuleModel_.columnCount();