From c83bbafbbc422e484f42ef4c18aa1b2d2e849d51 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Tue, 7 Mar 2017 03:02:28 -0500 Subject: [PATCH] gc: stream all errors including the last and report "encountered errors during gc run" as the response error License: MIT Signed-off-by: Kevin Atkinson --- core/commands/repo.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/commands/repo.go b/core/commands/repo.go index 8e4b3fc10..6e929f6e0 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -74,28 +74,26 @@ order to reclaim hard disk space. go func() { defer close(outChan) - unreportedError := false - var lastErr error if streamErrors { + errs := false for res := range gcOutChan { - if unreportedError { - outChan <- &GcResult{Error: lastErr.Error()} - unreportedError = false - } if res.Error != nil { - lastErr = res.Error - unreportedError = true + outChan <- &GcResult{Error: res.Error.Error()} + errs = true } else { outChan <- &GcResult{Key: res.KeyRemoved} } } + if errs { + res.SetError(fmt.Errorf("encountered errors during gc run"), cmds.ErrNormal) + } } else { - lastErr = corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) { + err := corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) { outChan <- &GcResult{Key: k} }) - } - if lastErr != nil { - res.SetError(lastErr, cmds.ErrNormal) + if err != nil { + res.SetError(err, cmds.ErrNormal) + } } }() },