From 8889e70c8b3e534058340aac1e6ace80767d0ffc Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 2 Jun 2021 10:54:30 +0200 Subject: [PATCH] Improve index updating error handling --- updater/updating.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/updater/updating.go b/updater/updating.go index 1283313..246143b 100644 --- a/updater/updating.go +++ b/updater/updating.go @@ -15,20 +15,26 @@ import ( "github.com/safing/portbase/log" ) -// UpdateIndexes downloads all indexes and returns the first error encountered. +// UpdateIndexes downloads all indexes. An error is only returned when all +// indexes fail to update. func (reg *ResourceRegistry) UpdateIndexes(ctx context.Context) error { - var firstErr error + var lastErr error + var anySuccess bool client := &http.Client{} for _, idx := range reg.getIndexes() { if err := reg.downloadIndex(ctx, client, idx); err != nil { - if firstErr == nil { - firstErr = err - } + lastErr = err + log.Warningf("%s: failed to update index %s: %s", reg.Name, idx.Path, err) + } else { + anySuccess = true } } - return firstErr + if !anySuccess { + return fmt.Errorf("failed to update all indexes, last error was: %s", lastErr) + } + return nil } func (reg *ResourceRegistry) downloadIndex(ctx context.Context, client *http.Client, idx Index) error {