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

Updated error message when hit "not found error" in gitprovider #1048

Merged
merged 7 commits into from
Nov 10, 2021

Conversation

josecordaz
Copy link
Contributor

@josecordaz josecordaz commented Nov 8, 2021

Closes: #1001

What changed?
Updated error message.
From:

Error: failed to get git clients: error setting up deploy keys: error uploading deploy key: error uploading deploy key multiple errors occurred:
- POST https://api.github.com/repos/stefanprodan/podinfo/keys: 404 Not Found []
- the requested resource was not found

To:

Error: failed to get git clients: error setting up deploy keys: error uploading deploy key: no permissions to access this repository or repository doesn't exists

Why?
There was confusion when distinguishing between if there were not enough permissions and if the repository does not exist.

How did you test it?
Added unit tests

Release notes

Documentation Changes

@josecordaz josecordaz added the type/enhancement New feature or request label Nov 8, 2021
@josecordaz josecordaz marked this pull request as ready for review November 9, 2021 15:32
@josecordaz josecordaz requested review from luizbafilho, jpellizzari and jrryjcksn and removed request for jpellizzari November 9, 2021 15:35
@@ -137,6 +137,13 @@ var _ = Describe("Org Provider", func() {
Expect(err.Error()).Should(ContainSubstring("error uploading deploy key"))
})

It("return error when it fails to upload a deploy key", func() {

Choose a reason for hiding this comment

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

👍

pkg/gitproviders/provider_user_test.go Outdated Show resolved Hide resolved
@@ -89,7 +91,11 @@ func deployKeyExists(ctx context.Context, repo gitprovider.UserRepository) (bool
func uploadDeployKey(ctx context.Context, repo gitprovider.UserRepository, deployKeyInfo gitprovider.DeployKeyInfo) error {
_, err := repo.DeployKeys().Create(ctx, deployKeyInfo)
if err != nil {
return fmt.Errorf("error uploading deploy key %s", err)
if errors.Is(err, gitprovider.ErrNotFound) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in general in Go we should use else clauses unless strictly necessary, which is not the case here since we call return in the if, so a suggestion would be changing to:

if errors.Is(err, gitprovider.ErrNotFound) {
	return RepositoryNoPermissionsOrDoesNotExistError
}

return fmt.Errorf("error uploading deploy key %s", err)

@@ -25,6 +25,8 @@ const (
defaultTimeout = time.Second * 30
)

var RepositoryNoPermissionsOrDoesNotExistError = errors.New("no permissions to access this repository or repository doesn't exists")
Copy link
Contributor

Choose a reason for hiding this comment

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

major: errors are prefixed with the Err like in gitprovider.ErrNotFound and the error types are suffixed with the Error

@josecordaz josecordaz merged commit c77ff99 into main Nov 10, 2021
@josecordaz josecordaz deleted the 1001-clearer-permissions-messages branch November 10, 2021 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide clearer guidance when gitops app add . command fails due to lack of permissions on target repo
3 participants