fix error propagation, small cleanup

pull/179/head
Simon Let 4 years ago
parent 0fcad6310c
commit ae9c182f93
No known key found for this signature in database
GPG Key ID: D650C65DD46D431D
  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
}
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))
go h.loadCliRecords(history)
// 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
func LoadFromFile(fname string, limit int) []Record {
const allowedErrors = 1
func LoadFromFile(fname string) []Record {
const allowedErrors = 2
var encounteredErrors int
// NOTE: limit does nothing atm
var recs []Record
@ -528,7 +528,8 @@ func LoadFromFile(fname string, limit int) []Record {
var i int
var firstErrLine int
for {
line, err := reader.ReadString('\n')
var line string
line, err = reader.ReadString('\n')
if err != nil {
break
}
@ -553,7 +554,6 @@ func LoadFromFile(fname string, limit int) []Record {
}
recs = append(recs, record)
}
// log.Println("records: done loading file:", err)
if err != io.EOF {
log.Println("records: error while loading file:", err)
}

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

Loading…
Cancel
Save