From 4cc89a5a32bd3623a065765637d5c08641e2a251 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 3 Feb 2020 16:22:46 +0100 Subject: [PATCH] internal/build: don't crash in DownloadFile when offline (#20595) --- internal/build/download.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/build/download.go b/internal/build/download.go index c50680029..0ed0b5e13 100644 --- a/internal/build/download.go +++ b/internal/build/download.go @@ -83,8 +83,10 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error { fmt.Printf("downloading from %s\n", url) resp, err := http.Get(url) - if err != nil || resp.StatusCode != http.StatusOK { - return fmt.Errorf("download error: code %d, err %v", resp.StatusCode, err) + if err != nil { + return fmt.Errorf("download error: %v", err) + } else if resp.StatusCode != http.StatusOK { + return fmt.Errorf("download error: status %d", resp.StatusCode) } defer resp.Body.Close() if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {