-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🌱 Use errors package of Go #10875
base: main
Are you sure you want to change the base?
🌱 Use errors package of Go #10875
Conversation
This PR is currently missing an area label, which is used to identify the modified component when generating release notes. Area labels can be added by org members by writing Please see the labels list for possible areas. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
generally seems better to use Is() and As() instead of the type assertions.
switch err { | ||
case errNoControlPlaneNodes, errLastControlPlaneNode, errNilNodeRef, errClusterIsBeingDeleted, errControlPlaneIsBeingDeleted: | ||
switch { | ||
case is(err): |
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.
isKnownError or something more descriptive, also you can inline the function inside reconcileDelete
@@ -61,6 +61,8 @@ var ( | |||
retryableOperationTimeout = 1 * time.Minute | |||
) | |||
|
|||
var rateLimitError github.RateLimitError |
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.
can be a local var in getVersions()?
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.
rateLimitError is used in many func of repository package. So I think it's better to prevent omission of change.
@@ -334,7 +336,7 @@ func (g *gitHubRepository) getVersions(ctx context.Context) ([]string, error) { | |||
if listReleasesErr != nil { | |||
retryError = g.handleGithubErr(listReleasesErr, "failed to get the list of releases") | |||
// Return immediately if we are rate limited. | |||
if _, ok := listReleasesErr.(*github.RateLimitError); ok { | |||
if errors.As(listReleasesErr, &rateLimitError) { |
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.
why not use errors.Is(....,, RateLimitError)?
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.
This code is originally type assertion, so errors.As is better than using errors.Is
@@ -305,7 +305,8 @@ func getGitHubClient(ctx context.Context, configVariablesClient config.Variables | |||
|
|||
// handleGithubErr wraps error messages. | |||
func handleGithubErr(err error, message string, args ...interface{}) error { | |||
if _, ok := err.(*github.RateLimitError); ok { | |||
var rateLimitErr *github.RateLimitError | |||
if errors.As(err, &rateLimitErr) { |
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.
why not use errors.Is(....,, RateLimitError)?
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.
Same reason, thanks.
/assign |
e594fc8
to
d75a32f
Compare
d75a32f
to
5f7ac82
Compare
Signed-off-by: sivchari <[email protected]>
Signed-off-by: sivchari <[email protected]>
5f7ac82
to
2f50f5b
Compare
I currently don't find the time to review this PR. Just one comment, we have to be really really sure this doesn't break anything accidentally (by catching more or less errors than before) |
What this PR does / why we need it:
Go has errors package to use Is() and As(). These API can check recursively if the err is one we want.
So I use errors package to check recursively.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #