-
Notifications
You must be signed in to change notification settings - Fork 153
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
Conversation
…nction between not finding a key, not having permissions or the repository doesn't exist.
…ror when creating deploy key
@@ -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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -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) { |
There was a problem hiding this comment.
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)
pkg/gitproviders/provider.go
Outdated
@@ -25,6 +25,8 @@ const ( | |||
defaultTimeout = time.Second * 30 | |||
) | |||
|
|||
var RepositoryNoPermissionsOrDoesNotExistError = errors.New("no permissions to access this repository or repository doesn't exists") |
There was a problem hiding this comment.
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
Closes: #1001
What changed?
Updated error message.
From:
To:
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