Skip to content

Commit

Permalink
fix: add error message for close stream and file
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 11, 2023
1 parent 2bdd253 commit 7fe268f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions utils/utils.go
Expand Up @@ -35,16 +35,20 @@ func DownloadWithProgress(url string, tarName string, destFolder string) (err er
}

defer func(body io.ReadCloser) {
_ = body.Close()
if err = body.Close(); err != nil {
color.Errorln("==> [Error]: failed close response body", err.Error())
}
}(resp.Body)

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s returned status code %d", url, resp.StatusCode)
}

f, _ := os.OpenFile(destTarPath, os.O_CREATE|os.O_WRONLY, 0644)
f, _ := os.OpenFile(destTarPath, os.O_CREATE|os.O_WRONLY, 0o644)
defer func(f *os.File) {
_ = f.Close()
if err = f.Close(); err != nil {
color.Errorln("==> [Error]: failed close file", err.Error())
}
}(f)

bar := progressbar.DefaultBytes(
Expand Down

0 comments on commit 7fe268f

Please sign in to comment.