@@ -29,6 +29,7 @@ import (
29
29
)
30
30
31
31
var regex * regexp.Regexp = regexp .MustCompile ("^([[:alnum:]]+)([.])(member|admin)$" )
32
+ var regexErr * regexp.Regexp = regexp .MustCompile ("^No parameter '([^']+)' found[.]$" )
32
33
33
34
func and (args ... interface {}) (interface {}, error ) {
34
35
toret := "outof(" + strconv .Itoa (len (args ))
@@ -209,8 +210,16 @@ func FromString(policy string) (*common.SignaturePolicyEnvelope, error) {
209
210
return nil , err
210
211
}
211
212
212
- intermediateRes , err := intermediate .Evaluate (nil )
213
+ intermediateRes , err := intermediate .Evaluate (map [ string ] interface {}{} )
213
214
if err != nil {
215
+ // attempt to produce a meaningful error
216
+ if regexErr .MatchString (err .Error ()) {
217
+ sm := regexErr .FindStringSubmatch (err .Error ())
218
+ if len (sm ) == 2 {
219
+ return nil , fmt .Errorf ("unrecognized token '%s' in policy string" , sm [1 ])
220
+ }
221
+ }
222
+
214
223
return nil , err
215
224
}
216
225
@@ -225,8 +234,16 @@ func FromString(policy string) (*common.SignaturePolicyEnvelope, error) {
225
234
return nil , err
226
235
}
227
236
228
- res , err := exp .Evaluate (nil )
237
+ res , err := exp .Evaluate (map [ string ] interface {}{} )
229
238
if err != nil {
239
+ // attempt to produce a meaningful error
240
+ if regexErr .MatchString (err .Error ()) {
241
+ sm := regexErr .FindStringSubmatch (err .Error ())
242
+ if len (sm ) == 2 {
243
+ return nil , fmt .Errorf ("unrecognized token '%s' in policy string" , sm [1 ])
244
+ }
245
+ }
246
+
230
247
return nil , err
231
248
}
232
249
@@ -241,6 +258,14 @@ func FromString(policy string) (*common.SignaturePolicyEnvelope, error) {
241
258
242
259
res , err = exp .Evaluate (parameters )
243
260
if err != nil {
261
+ // attempt to produce a meaningful error
262
+ if regexErr .MatchString (err .Error ()) {
263
+ sm := regexErr .FindStringSubmatch (err .Error ())
264
+ if len (sm ) == 2 {
265
+ return nil , fmt .Errorf ("unrecognized token '%s' in policy string" , sm [1 ])
266
+ }
267
+ }
268
+
244
269
return nil , err
245
270
}
246
271
0 commit comments