Merge pull request #84 from adambhayes/master

Bugfix for crashing on saved invalid filter
master
Brandon Lee Camilleri 3 years ago committed by GitHub
commit 4ee7518d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 1
      cmd/mop/main.go
  3. 12
      filter.go
  4. 1
      profile.go

@ -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 ###

@ -143,4 +143,5 @@ func main() {
profile := mop.NewProfile(*profileName)
mainLoop(screen, profile)
profile.Save()
}

@ -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 {

@ -142,5 +142,4 @@ func (profile *Profile) SetFilter(filter string) {
}
profile.Filter = filter
profile.Save()
}

Loading…
Cancel
Save