forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
81 lines (64 loc) · 2.21 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package ldaputil
import (
"fmt"
"gopkg.in/ldap.v2"
)
func NewNoSuchObjectError(baseDN string) error {
return &errNoSuchObject{baseDN: baseDN}
}
// errNoSuchObject is an error that occurs when a base DN for a search refers to an object that does not exist
type errNoSuchObject struct {
baseDN string
}
// Error returns the error string for the invalid base DN query error
func (e *errNoSuchObject) Error() string {
return fmt.Sprintf("search for entry with base dn=%q refers to a non-existent entry", e.baseDN)
}
// IsNoSuchObjectError determines if the error is a NoSuchObjectError or if it is the upstream version of the error
// If this returns true, you are *not* safe to cast the error to a NoSuchObjectError
func IsNoSuchObjectError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*errNoSuchObject)
return ok || ldap.IsErrorWithCode(err, ldap.LDAPResultNoSuchObject)
}
func NewEntryNotFoundError(baseDN, filter string) error {
return &errEntryNotFound{baseDN: baseDN, filter: filter}
}
// errEntryNotFound is an error that occurs when trying to find a specific entry fails.
type errEntryNotFound struct {
baseDN string
filter string
}
// Error returns the error string for the entry not found error
func (e *errEntryNotFound) Error() string {
return fmt.Sprintf("search for entry with base dn=%q and filter %q did not return any results", e.baseDN, e.filter)
}
func IsEntryNotFoundError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*errEntryNotFound)
return ok
}
func NewQueryOutOfBoundsError(queryDN, baseDN string) error {
return &errQueryOutOfBounds{baseDN: baseDN, queryDN: queryDN}
}
// errQueryOutOfBounds is an error that occurs when trying to search by DN for an entry that exists
// outside of the tree specified with the BaseDN for search.
type errQueryOutOfBounds struct {
baseDN string
queryDN string
}
// Error returns the error string for the out-of-bounds query
func (q *errQueryOutOfBounds) Error() string {
return fmt.Sprintf("search for entry with dn=%q would search outside of the base dn specified (dn=%q)", q.queryDN, q.baseDN)
}
func IsQueryOutOfBoundsError(err error) bool {
if err == nil {
return false
}
_, ok := err.(*errQueryOutOfBounds)
return ok
}