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

fix: Optimize image deletion error return #7602

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Conversation

ssongliu
Copy link
Member

Refs #7068

Copy link

f2c-ci-robot bot commented Dec 30, 2024

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
Copy link
Member

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:

  1. Consistent Naming: Ensure all constant names follow consistent naming conventions (e.g., use underscores to separate words).

  2. Avoid Ambiguity: Clearly differentiate between "in_use" and "be_dependent". The name ErrObjectBeDependent could be clearer.

  3. Error Messages: While clear error messages are important and should communicate effectively, they can sometimes become long and cumbersome if excessively detailed.

  4. 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.

  5. 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
}
}
Copy link
Member

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!

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

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

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Dec 30, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit fc401ff into dev Dec 30, 2024
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@feat_image_remove branch December 30, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants