From 2b485512c0985a79639737e08ae4095e8d89486f Mon Sep 17 00:00:00 2001 From: Benoit Gagnon Date: Sat, 28 Sep 2019 11:40:09 -0400 Subject: [PATCH] improve github archive download error reporting --- pkg/git.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/git.go b/pkg/git.go index e7ebfb5..5a9e65e 100644 --- a/pkg/git.go +++ b/pkg/git.go @@ -52,15 +52,22 @@ func downloadGitHubArchive(filepath string, url string) (string, error) { return "", err } color.Cyan("GET %s %d", url, resp.StatusCode) + if resp.StatusCode != 200 { + return "", errors.New(fmt.Sprintf("unexpected status code %d", resp.StatusCode)) + } // GitHub conveniently uses the commit SHA1 at the ETag // signature for the archive. This is needed when doing `jb update` // to resolve a ref (ie. "master") to a commit SHA1 for the lock file etagValue := resp.Header.Get(http.CanonicalHeaderKey("ETag")) + if etagValue == "" { + return "", errors.New("ETag header is missing from response") + } + commitShaPattern, _ := regexp.Compile("^\"([0-9a-f]{40})\"$") m := commitShaPattern.FindStringSubmatch(etagValue) if len(m) < 2 { - return "", errors.New(fmt.Sprintf("unexpected etag format: %s", etagValue)) + return "", errors.New(fmt.Sprintf("etag value \"%s\" does not look like a SHA1", etagValue)) } commitSha := m[1] defer resp.Body.Close()