Skip to content

Commit da547b4

Browse files
github-actions[bot]bupd
authored andcommitted
upstream: fix: use errors.Is for sentinel error checks in usergroup controller (goharbor/harbor#23636)
Replace direct error equality comparisons (==) with errors.Is() in the usergroup controller. This ensures correct behavior when sentinel errors are wrapped, following Go best practices introduced in Go 1.13. The errors package from Harbor's lib/errors already re-exports errors.Is, so no additional imports are needed. Changes: - err == ldap.ErrNotFound -> errors.Is(err, ldap.ErrNotFound) - err == ldap.ErrDNSyntax -> errors.Is(err, ldap.ErrDNSyntax) - err != nil && err == usergroup.ErrDupUserGroup -> errors.Is(err, usergroup.ErrDupUserGroup) Signed-off-by: Norway-02 <anshulkhetade02@gmail.com> Co-authored-by: Wang Yan <wangyan_0219@hotmail.com> (cherry picked from commit 2020f8d) Upstream-Commit: 2020f8d Upstream-PR: goharbor/harbor#23636 Upstream-Author: @Norway-02 Cherry-Pick-Status: clean Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> (cherry picked from commit ef9e319) Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4421c03 commit da547b4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/controller/usergroup/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ func (c *controller) Update(ctx context.Context, id int, groupName string) error
9191
func (c *controller) Create(ctx context.Context, group model.UserGroup) (int, error) {
9292
if group.GroupType == common.LDAPGroupType {
9393
ldapGroup, err := auth.SearchGroup(ctx, group.LdapGroupDN)
94-
if err == ldap.ErrNotFound || ldapGroup == nil {
94+
if errors.Is(err, ldap.ErrNotFound) || ldapGroup == nil {
9595
return 0, errors.BadRequestError(nil).WithMessagef("LDAP Group DN is not found: DN:%v", group.LdapGroupDN)
9696
}
97-
if err == ldap.ErrDNSyntax {
97+
if errors.Is(err, ldap.ErrDNSyntax) {
9898
return 0, errors.BadRequestError(nil).WithMessagef("invalid DN syntax. DN: %v", group.LdapGroupDN)
9999
}
100100
if err != nil {
101101
return 0, err
102102
}
103103
}
104104
id, err := c.mgr.Create(ctx, group)
105-
if err != nil && err == usergroup.ErrDupUserGroup {
105+
if errors.Is(err, usergroup.ErrDupUserGroup) {
106106
return 0, errors.ConflictError(nil).
107107
WithMessagef("duplicate user group, group name:%v, group type: %v, ldap group DN: %v",
108108
group.GroupName, group.GroupType, group.LdapGroupDN)

0 commit comments

Comments
 (0)