From 344c6526a8d6f490fc7628ddc7d2dd06ed1a07c1 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Tue, 22 Jul 2025 15:41:03 -0400 Subject: Separate program entry point from commands --- pkg/index/filters.go | 4 ++-- pkg/index/index.go | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'pkg/index') diff --git a/pkg/index/filters.go b/pkg/index/filters.go index 920d5df..bd9df54 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -50,10 +50,10 @@ func ParseFilter(s string) (DocFilter, error) { } return NewMaxFilesizeFilter(size), nil case "ExcludeName", "ExcludeFilename": - // FIXME: support escaped commas + // TODO: support escaped commas return NewExcludeFilenameFilter(strings.Split(param, ",")), nil case "IncludeName", "IncludeFilename": - // FIXME: support escaped commas + // TODO: support escaped commas return NewIncludeFilenameFilter(strings.Split(param, ",")), nil case "ExcludeParent": return NewExcludeParentFilter(param), nil diff --git a/pkg/index/index.go b/pkg/index/index.go index cfa4138..50f642e 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -12,6 +12,7 @@ import ( "slices" "strings" "sync" + "sync/atomic" "time" "github.com/goccy/go-yaml" @@ -383,21 +384,23 @@ func ParseDoc(path string, opts ParseOpts) (*Document, error) { return doc, nil } -func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) map[string]*Document { +func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) (map[string]*Document, uint64) { jobs := make(chan string, numWorkers) results := make(chan *Document, numWorkers) docs := make(map[string]*Document, len(paths)) wg := &sync.WaitGroup{} + errCnt := &atomic.Uint64{} wg.Add(int(numWorkers)) for range numWorkers { go func(jobs <-chan string, results chan<- *Document, wg *sync.WaitGroup) { for path := range jobs { doc, err := ParseDoc(path, opts) if err != nil { - slog.Error("Error occured while parsing file", + slog.Warn("Error occured while parsing file", slog.String("path", path), slog.String("err", err.Error()), ) + errCnt.Add(1) continue } @@ -423,7 +426,7 @@ func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) map[string]*Docu docs[doc.Path] = doc } - return docs + return docs, errCnt.Load() } func init() { -- cgit v1.2.3