-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix: Optimize image deletion error return #7602
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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/test-infra repository. |
ErrObjectInUsed = "ErrObjectInUsed" | ||
ErrObjectBeDependent = "ErrObjectBeDependent" | ||
ErrPortRules = "ErrPortRules" | ||
ErrPgImagePull = "ErrPgImagePull" | ||
) | ||
|
||
// runtime |
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.
The code you've provided is primarily defining constants for error messages in Go using the var
keyword. There are no specific errors listed in your code snippet that indicate a problem or require further optimization. However, here are some general guidelines for maintaining clean and efficient constant definitions:
-
Consistent Naming: Ensure all constant names follow consistent naming conventions (e.g., use underscores to separate words).
-
Avoid Ambiguity: Clearly differentiate between "in_use" and "be_dependent". The name
ErrObjectBeDependent
could be clearer. -
Error Messages: While clear error messages are important and should communicate effectively, they can sometimes become long and cumbersome if excessively detailed.
-
Reusability: Consider whether these error strings will need to change frequently or across different versions of your application. If so, it might be beneficial to store them in environment variables or configuration files instead of hardcoding them into your source code.
-
Documentation: Include comments explaining each constant and what each represents. This is particularly useful for other developers who may work on this code in the future.
Overall, your code structure looks neat and maintainable for the purpose of defining error messages in a struct.
@@ -439,6 +439,9 @@ func (u *ImageService) ImageRemove(req dto.BatchDelete) error { | |||
} | |||
return buserr.WithDetail(constant.ErrInUsed, id, nil) | |||
} | |||
if strings.Contains(err.Error(), "image has dependent") { | |||
return buserr.New(constant.ErrObjectBeDependent) | |||
} | |||
return 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.
The added conditional statement checks if the error message contains "image has dependent" and returns constant.ErrObjectBeDependent
if true. This appears to be an optimized solution to check for specific conditions that can cause errors during image removal, improving efficiency by reducing redundant checks elsewhere in the function.
If you have more changes or need further assistance, feel free to ask!
Quality Gate passedIssues Measures |
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.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Refs #7068