From ae9c182f932d6d573e94d801cd7cfb0d2f9e6a87 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Wed, 20 Apr 2022 02:25:44 +0200 Subject: [PATCH] fix error propagation, small cleanup --- pkg/histfile/histfile.go | 2 +- pkg/records/records.go | 8 ++++---- pkg/searchapp/test.go | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/histfile/histfile.go b/pkg/histfile/histfile.go index 73e5309..17e7ffb 100644 --- a/pkg/histfile/histfile.go +++ b/pkg/histfile/histfile.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 diff --git a/pkg/records/records.go b/pkg/records/records.go index 6271ba5..411afd6 100644 --- a/pkg/records/records.go +++ b/pkg/records/records.go @@ -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) } diff --git a/pkg/searchapp/test.go b/pkg/searchapp/test.go index e33e2f7..30b850f 100644 --- a/pkg/searchapp/test.go +++ b/pkg/searchapp/test.go @@ -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] }