fix error propagation, small cleanup

pull/184/head
Simon Let 4 years ago committed by Simon Let
parent eb52d666d9
commit c60d1bcd33
  1. 2
      pkg/histfile/histfile.go
  2. 8
      pkg/records/records.go
  3. 4
      pkg/searchapp/test.go

@ -88,7 +88,7 @@ func (h *Histfile) loadHistory(bashHistoryPath, zshHistoryPath string, maxInitHi
maxInitHistSize = math.MaxInt32 maxInitHistSize = math.MaxInt32
} }
log.Println("histfile: Loading resh history from file ...") log.Println("histfile: Loading resh history from file ...")
history := records.LoadFromFile(h.historyPath, math.MaxInt32) history := records.LoadFromFile(h.historyPath)
log.Println("histfile: resh history loaded from file - count:", len(history)) log.Println("histfile: resh history loaded from file - count:", len(history))
go h.loadCliRecords(history) go h.loadCliRecords(history)
// NOTE: keeping this weird interface for now because we might use it in the future // NOTE: keeping this weird interface for now because we might use it in the future

@ -511,8 +511,8 @@ func (r *EnrichedRecord) DistanceTo(r2 EnrichedRecord, p DistParams) float64 {
} }
// LoadFromFile loads records from 'fname' file // LoadFromFile loads records from 'fname' file
func LoadFromFile(fname string, limit int) []Record { func LoadFromFile(fname string) []Record {
const allowedErrors = 1 const allowedErrors = 2
var encounteredErrors int var encounteredErrors int
// NOTE: limit does nothing atm // NOTE: limit does nothing atm
var recs []Record var recs []Record
@ -528,7 +528,8 @@ func LoadFromFile(fname string, limit int) []Record {
var i int var i int
var firstErrLine int var firstErrLine int
for { for {
line, err := reader.ReadString('\n') var line string
line, err = reader.ReadString('\n')
if err != nil { if err != nil {
break break
} }
@ -553,7 +554,6 @@ func LoadFromFile(fname string, limit int) []Record {
} }
recs = append(recs, record) recs = append(recs, record)
} }
// log.Println("records: done loading file:", err)
if err != io.EOF { if err != io.EOF {
log.Println("records: error while loading file:", err) log.Println("records: error while loading file:", err)
} }

@ -1,8 +1,6 @@
package searchapp package searchapp
import ( import (
"math"
"github.com/curusarn/resh/pkg/histcli" "github.com/curusarn/resh/pkg/histcli"
"github.com/curusarn/resh/pkg/msg" "github.com/curusarn/resh/pkg/msg"
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
@ -10,7 +8,7 @@ import (
// LoadHistoryFromFile ... // LoadHistoryFromFile ...
func LoadHistoryFromFile(historyPath string, numLines int) msg.CliResponse { func LoadHistoryFromFile(historyPath string, numLines int) msg.CliResponse {
recs := records.LoadFromFile(historyPath, math.MaxInt32) recs := records.LoadFromFile(historyPath)
if numLines != 0 && numLines < len(recs) { if numLines != 0 && numLines < len(recs) {
recs = recs[:numLines] recs = recs[:numLines]
} }

Loading…
Cancel
Save