all repos — searchix @ 16f488de7dc8e0bb34ffadad167b443b803c8b73

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor: extract batch handling into struct

Alan Pearce
commit

16f488de7dc8e0bb34ffadad167b443b803c8b73

parent

e055ed6177bdec5fb286724a8e6b6e8ad715cca1

1 file changed, 14 insertions(+), 6 deletions(-)

changed files
M internal/importer/options.gointernal/importer/options.go
@@ -79,6 +79,9 @@ return func(yield func(index.Indexable) bool) {
defer i.infile.Close() for mv := range i.dec.Stream() { + if ctx.Err() != nil { + break + } if err := i.dec.Err(); err != nil { i.errs = append(i.errs, fault.Wrap(err, fmsg.With("could not decode JSON")))
@@ -102,9 +105,10 @@ case string:
s := decl link, err := MakeChannelLink(i.source.Repo, s) if err != nil { - i.errs = append(i.errs, fault.Wrap(err, fmsg.Withf("could not make a channel link for channel %s, revision %s and subpath %s", - i.source.Channel, i.source.Repo.Revision, s, - ))) + i.errs = append(i.errs, + fault.Wrap(err, fmsg.Withf("could not make a channel link for channel %s, revision %s and subpath %s", + i.source.Channel, i.source.Repo.Revision, s, + ))) continue }
@@ -183,11 +187,15 @@ }
} func (i *OptionIngester) Err() error { - if len(i.errs) == 0 { + errs := i.errs + if len(errs) == 0 { return nil } - if len(i.errs) == 1 { + if len(errs) == 1 { return i.errs[0] } - return fault.Newf("encountered %d errors during processing", len(i.errs)) + + i.errs = []error{} + + return fault.Newf("encountered %d errors during processing", len(errs)) }