fix(ldap): split ambiguous error messages in SearchDN and GetEntry
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Distinguish between "not found" and "multiple entries found" instead of the generic "User does not exist or too many entries returned", making it easier to diagnose issues in logs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f517be8afb
commit
e6bca3ac8f
1 changed files with 10 additions and 5 deletions
15
ldap.go
15
ldap.go
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/rand"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -99,8 +98,11 @@ func (l LDAPConn) SearchDN(username string, person bool) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
if len(sr.Entries) != 1 {
|
||||
return "", errors.New("User does not exist or too many entries returned")
|
||||
if len(sr.Entries) == 0 {
|
||||
return "", fmt.Errorf("user %q not found", username)
|
||||
}
|
||||
if len(sr.Entries) > 1 {
|
||||
return "", fmt.Errorf("multiple entries (%d) found for user %q", len(sr.Entries), username)
|
||||
}
|
||||
|
||||
return sr.Entries[0].DN, nil
|
||||
|
|
@ -118,8 +120,11 @@ func (l LDAPConn) GetEntry(dn string) ([]*ldap.EntryAttribute, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(sr.Entries) != 1 {
|
||||
return nil, errors.New("User does not exist or too many entries returned")
|
||||
if len(sr.Entries) == 0 {
|
||||
return nil, fmt.Errorf("entry not found for DN %q", dn)
|
||||
}
|
||||
if len(sr.Entries) > 1 {
|
||||
return nil, fmt.Errorf("multiple entries (%d) found for DN %q", len(sr.Entries), dn)
|
||||
}
|
||||
|
||||
return sr.Entries[0].Attributes, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue