Chore: Check errors from Close calls (#29562)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-12-03 10:11:14 +01:00
committed by GitHub
parent 3c9310e93c
commit f2b7fbc32a
14 changed files with 109 additions and 33 deletions
+9 -1
View File
@@ -96,7 +96,12 @@ func (rs *RenderingService) renderViaHttp(ctx context.Context, renderKey string,
if err != nil {
return nil, err
}
defer out.Close()
defer func() {
if err := out.Close(); err != nil {
// We already close the file explicitly in the non-error path, so shouldn't be a problem
rs.log.Warn("Failed to close file", "path", filePath, "err", err)
}
}()
_, err = io.Copy(out, resp.Body)
if err != nil {
// check that we didn't timeout while receiving the response.
@@ -107,6 +112,9 @@ func (rs *RenderingService) renderViaHttp(ctx context.Context, renderKey string,
rs.log.Error("Remote rendering request failed", "error", err)
return nil, fmt.Errorf("remote rendering request failed: %w", err)
}
if err := out.Close(); err != nil {
return nil, fmt.Errorf("failed to write to %q: %w", filePath, err)
}
return &RenderResult{FilePath: filePath}, err
}