From bff66ef176ebf6725c8dea71782a0ae18c3472a5 Mon Sep 17 00:00:00 2001 From: Adam Hayes Date: Tue, 23 Nov 2021 21:13:40 -0500 Subject: [PATCH 1/2] Corrected build instructions in README.md Changed "go build ./mop/cmd" to "go build ./cmd/mop" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ebeaa1..544ecf9 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Alternatively, $ git clone https://github.com/mop-tracker/mop $ cd mop - $ go build ./mop/cmd + $ go build ./cmd/mop $ ./mop ### Using Mop ### From 635e467e7a5732b04c2ec29ad0293729e5c30bd4 Mon Sep 17 00:00:00 2001 From: Adam Hayes Date: Tue, 23 Nov 2021 22:47:53 -0500 Subject: [PATCH 2/2] Added fixes for crashing on bad filter * Does not save profile in the SetFilter function. * Saves profile on exit (exit from main loop). * Clears filter string if it is found to be invalid in the Apply function. --- cmd/mop/main.go | 1 + filter.go | 12 ++++++++++-- profile.go | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/mop/main.go b/cmd/mop/main.go index 3c5ff72..7c64b77 100644 --- a/cmd/mop/main.go +++ b/cmd/mop/main.go @@ -143,4 +143,5 @@ func main() { profile := mop.NewProfile(*profileName) mainLoop(screen, profile) + profile.Save() } diff --git a/filter.go b/filter.go index 4cdf61b..f79decc 100644 --- a/filter.go +++ b/filter.go @@ -50,13 +50,21 @@ func (filter *Filter) Apply(stocks []Stock) []Stock { result, err := filter.profile.filterExpression.Evaluate(values) if err != nil { - panic(err) + // The filter isn't working, so reset to no filter. + filter.profile.Filter = "" + // Return an empty list. The next main loop cycle will + // show unfiltered. + return filteredStocks } truthy, ok := result.(bool) if !ok { - panic("Expression `" + filter.profile.Filter + "` should return a boolean value") + // The filter isn't working, so reset to no filter. + filter.profile.Filter = "" + // Return an empty list. The next main loop cycle will + // show unfiltered. + return filteredStocks } if truthy { diff --git a/profile.go b/profile.go index 6bb3c1e..ce393ed 100644 --- a/profile.go +++ b/profile.go @@ -142,5 +142,4 @@ func (profile *Profile) SetFilter(filter string) { } profile.Filter = filter - profile.Save() }