This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
err.go
280 lines (231 loc) · 7.38 KB
/
err.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package aci
import (
"errors"
)
/*
errorf wraps errors.New and returns a non-nil instance of error
based upon a non-nil/non-zero msg input value with optional args.
*/
func errorf(msg any, x ...any) error {
switch tv := msg.(type) {
case string:
if len(tv) > 0 {
return errors.New(sprintf(tv, x...))
}
case error:
if tv != nil {
return errors.New(sprintf(tv.Error(), x...))
}
}
return nil
}
func nilInstanceErr(x any) error {
return errorf("%T instance is nil", x)
}
/*
badInhErr returns an error describing the appropriate syntax and displaying the offending value.
*/
func badInhErr(bad string) error {
return errorf("Bad Inheritance value '%s'; must conform to 'parent[0-9+].<at>#<bt_or_av>'", bad)
}
func badCopErr(instance any) error {
return errorf("%T contains an bogus underlying value", instance)
}
func badClockTimeErr(raw, thyme string) (err error) {
if thyme != raw {
err = errorf("Unexpected %s clock time parsing result; want '%s', got '%s' (hint: use military time; 0000 through 2400)",
BindToD, raw, thyme)
}
return
}
func badSecurityStrengthFactorErr(raw, fac string) (err error) {
if fac != raw {
err = errorf("Unexpected security strength factor parsing result; want '%s', got '%s' (hint: valid range is 0-256)",
raw, fac)
}
return
}
func unexpectedBindConditionValueErr(key BindKeyword, want, got int) (err error) {
if want != got {
err = errorf("Unexpected number of %s values; want %d, got %d", key, want, got)
}
return
}
func badIPErr(want, got int) (err error) {
if want != got {
err = errorf("Unexpected '%s' values parsed; want '%d', got '%d'", BindIP, want, got)
}
return
}
func badDNSErr(raw, fqdn string) (err error) {
if raw != fqdn {
err = errorf("Unexpected '%s' values parsed; want '%s', got '%s'", BindDNS, raw, fqdn)
}
return
}
func badAMErr(raw, am string) (err error) {
if !eq(am, raw) {
err = errorf("Unexpected %s auth method parsing result; want '%s', got '%s'", BindAM, raw, am)
}
return
}
func badPTBRuleKeywordErr(candidate any, typ string, want, got any) error {
var kw, kg string
switch tv := want.(type) {
case string:
kw = tv
case Keyword:
kw = tv.String()
}
switch tv := got.(type) {
case string:
kg = tv
case Keyword:
kg = tv.String()
}
emsg := "Unknown or unresolvable %s rule keyword or category for %T: want '%s', got '%s'"
return errorf(emsg, typ, candidate, kw, kg)
}
func noTBRuleExpressionValues(candidate any, typ string, key Keyword) error {
emsg := "Found no %s %s rule expression value(s) during %T assertion"
return errorf(emsg, key, typ, candidate)
}
func badAttributeBindTypeOrValueErr(x string) error {
return errorf("Invalid AttributeBindTyoeOrValue instance: must conform to '<at>#<bt_or_av>', got '%s'", x)
}
func badObjectIdentifierErr(x string) error {
return errorf("Invalid ObjectIdentifier instance: must conform to 'N[.N]+', got '%s'", x)
}
func badObjectIdentifierKeywordErr(key TargetKeyword) error {
emsg := "Invalid %s and/or %T[%s] value(s)"
return errorf(emsg, `ObjectIdentifier`, key, key)
}
func unexpectedKindErr(receiver any, want, got string) error {
return errorf("Unexpected %T.Kind result: should be '%s', got '%s'", receiver, want, got)
}
func illegalSliceTypeErr(receiver, want, got any) error {
return errorf("Illegal slice type within %T stack: should be '%T', got '%T'",
receiver, want, got)
}
func illegalSyntaxPerTypeErr(candidate any, key Keyword, er ...error) error {
var err error
var kw string = `<unspecified_keyword>`
if len(er) > 0 {
err = er[0]
}
if key != nil {
kw = key.String()
}
emsg := "%T [%s] syntax invalid"
if err != nil {
emsg += `: %v`
return errorf(emsg, candidate, kw, err)
}
return errorf(emsg, candidate, kw)
}
func afosNonIdempSplitErr(d, l, o int, c rune) error {
emsg := "Inappropriate delimiter id [%d]; non-idempotent result following '%c' split: len(vals)=%d, opct=%d"
return errorf(emsg, d, c, l, o)
}
func afoMissingPrefixErr() error {
emsg := "%T instance is missing required %T prefix: needs either add= or delete="
return errorf(emsg, AttributeFilterOperation{}, AttributeOperation(0))
}
func aoBadPrefixErr() error {
emsg := "Invalid %T value prefix; must be add= or delete="
return errorf(emsg, AttributeOperation(0))
}
func uriBadPrefixErr() error {
emsg := "Invalid %T value prefix; must be %s"
return errorf(emsg, LDAPURI{}, LocalScheme)
}
func afMissingDelimiterErr(af AttributeFilter) error {
emsg := "No attr:filter delimiter (%c) found in %T"
return errorf(emsg, ':', af)
}
func instructionNoLabelErr() error {
emsg := "%T has no name (ACL); set a string name value using %T.Set"
return errorf(emsg, Instruction{}, Instruction{})
}
func levelsNotFoundErr() error {
emsg := "No level identifiers parsed; aborting"
return errorf(emsg)
}
func rightNotfound(x string) error {
emsg := "Right '%s' unknown"
return errorf(emsg, x)
}
func dowBadTimeErr() error {
emsg := "%T instance describes invalid timeofday"
return errorf(emsg, TimeOfDay{})
}
func dowBadDayErr(x any) error {
emsg := "%T instance describes invalid dayofweek: %v"
return errorf(emsg, DayOfWeek{}, x)
}
func noPermissionDispErr() error {
emsg := "%T has no disposition (allow/deny), or is ambiguous (nil)"
return errorf(emsg, Permission{})
}
func fqdnInvalidLabelErr(l domainLabel) error {
emsg := "%T has a bad label %v"
return errorf(emsg, FQDN{}, l)
}
func fqdnInvalidLenErr(l int) error {
emsg := "%T size requirements not met (%d v. %d), or len < 2"
return errorf(emsg, FQDN{}, l, fqdnMax)
}
func parseBindRuleInvalidExprTypeErr(receiver, want, got any) error {
emsg := "Unexpected %T within %T; wanted %T"
return errorf(emsg, got, receiver, want)
}
func parseBindRulesHierErr(stk any, b BindContext) error {
emsg := "Unable to cast %T hierarchy into %T; aborting"
return errorf(emsg, stk, b)
}
func unexpectedStringResult(typ, want, got string) error {
emsg := "Unexpected string %s result; want %s, got %s"
return errorf(emsg, typ, want, got)
}
func unexpectedValueCountErr(typ string, want, got int) error {
emsg := "Unexpected number of %s values; want %d, got %d"
return errorf(emsg, typ, want, got)
}
func bogusValueErr(typ, bogus string) error {
emsg := "Bogus %s value: '%s'"
return errorf(emsg, typ, bogus)
}
func generalErr(typ string, err error) error {
emsg := "General %s error: %v"
return errorf(emsg, typ, err)
}
func noValueErr(candidate any, typ string) error {
emsg := "Found no %s expression during processing of %T instance"
return errorf(emsg, typ, candidate)
}
func pushError(receiver, candidate any, key Keyword, emsg string, er ...error) error {
var err error
var kw string = `<unspecified_keyword>`
if len(er) > 0 {
err = er[0]
}
if key != nil {
kw = key.String()
}
if err != nil {
return errorf(emsg, candidate, receiver, kw, err)
}
return errorf(emsg, candidate, receiver, kw)
}
func pushErrorNotUnique(receiver, candidate any, key Keyword, er ...error) error {
emsg := "Cannot push non-unique or ineligible %T into %T [%s]"
return pushError(receiver, candidate, key, emsg, er...)
}
func pushErrorNilOrZero(receiver, candidate any, key Keyword, er ...error) error {
var emsg string = "Cannot push zero-length or nil %T into %T [%s]: %v"
return pushError(receiver, candidate, key, emsg, er...)
}
func pushErrorBadType(receiver, candidate any, key Keyword, er ...error) error {
var emsg string = "Push request of %T type violates %T [%s] PushPolicy"
return pushError(receiver, candidate, key, emsg, er...)
}