Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit error return #2469

Merged
merged 4 commits into from Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion github/repos_contents.go
Expand Up @@ -317,5 +317,8 @@ func (s *RepositoriesService) GetArchiveLink(ctx context.Context, owner, repo st
}

parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), err
if err != nil {
return nil, newResponse(resp), err
}
return parsedURL, newResponse(resp), nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is another thing that is inconsistent across this repo, but while I'm thinking about it, let's go ahead and add a blank line between the error handling and the final return, please.

Suggested change
}
return parsedURL, newResponse(resp), nil
}
return parsedURL, newResponse(resp), nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Done.

}
17 changes: 17 additions & 0 deletions github/repos_contents_test.go
Expand Up @@ -744,6 +744,23 @@ func TestRepositoriesService_GetArchiveLink_StatusMovedPermanently_followRedirec
}
}

func TestRepositoriesService_GetArchiveLink_invalidLocationHeader(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/tarball", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
ctlChar := 0x7f
badURL := "https://google.com" + string(byte(ctlChar))
w.Header().Add("Location", badURL)
w.WriteHeader(http.StatusFound)
})

ctx := context.Background()
_, _, err := client.Repositories.GetArchiveLink(ctx, "o", "r", Tarball, &RepositoryContentGetOptions{}, false)
testURLParseError(t, err)
}

func TestRepositoriesService_GetContents_NoTrailingSlashInDirectoryApiPath(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down