From a53778cd8306b0c136a4aa2208c819f8a9a1842a Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Jan 2021 19:25:04 +0100 Subject: [PATCH] rest: handle dropped error in save operation --- internal/backend/rest/rest.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 76feb3a11..44fcaead6 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -132,15 +132,10 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea resp, err := ctxhttp.Do(ctx, b.client, req) b.sem.ReleaseToken() + var cerr error if resp != nil { - defer func() { - _, _ = io.Copy(ioutil.Discard, resp.Body) - e := resp.Body.Close() - - if err == nil { - err = errors.Wrap(e, "Close") - } - }() + _, _ = io.Copy(ioutil.Discard, resp.Body) + cerr = resp.Body.Close() } if err != nil { @@ -151,7 +146,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea return errors.Errorf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode) } - return nil + return errors.Wrap(cerr, "Close") } // ErrIsNotExist is returned whenever the requested file does not exist on the