From 4d16242133af99edd26e1760c47d2953440d8a9c Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sun, 3 Jan 2021 13:15:21 -0500 Subject: [PATCH] Better control of a display filter error message The pcap loader's NewFilter entrypoint is called in several places e.g. by the stream reassembly UI. But the fact that the filter being applied is the same as the current one is an error/warning only if the user applies it from the filter widget. So I don't want these errors displayed in other circumstances. --- pcap/loader.go | 8 -------- ui/ui.go | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pcap/loader.go b/pcap/loader.go index 8cb24cc..bfc23fe 100644 --- a/pcap/loader.go +++ b/pcap/loader.go @@ -432,14 +432,6 @@ func (c *PacketLoader) NewFilter(newfilt string, cb interface{}, app gowid.IApp) if c.DisplayFilter() == newfilt { log.Infof("No operation - same filter applied ('%s').", newfilt) - // This is a hack to avoid displaying an error in the following situation. The user loads - // a pcap and applies a filter. Then they hit clear-packets. The filter is still shown. - // Then they run clear-filter. That will attempt to apply a new filter, but the loader's - // record of the filter is cleared, and the new filter to apply is also clear, so they - // are the same, so this error is shown. - if newfilt != "" { - HandleError(NoneCode, app, fmt.Errorf("Same filter - nothing to do."), cb) - } } else { c.stopTail() c.stopLoadPsml() diff --git a/ui/ui.go b/ui/ui.go index ba9deae..8894474 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -2933,7 +2933,11 @@ func Build() (*gowid.App, error) { }) validFilterCb := gowid.MakeWidgetCallback("cb", func(app gowid.IApp, w gowid.IWidget) { - RequestNewFilter(FilterWidget.Value(), app) + if Loader.DisplayFilter() == FilterWidget.Value() { + OpenError("Same filter - nothing to do", app) + } else { + RequestNewFilter(FilterWidget.Value(), app) + } }) // Will only be enabled to click if filter is valid