Skip to content

Commit bc4eb1a

Browse files
authored
Show helpful error message if onnx predictor is specified (#2075)
1 parent 3ec0b63 commit bc4eb1a

File tree

14 files changed

+38
-8
lines changed

14 files changed

+38
-8
lines changed

pkg/lib/configreader/float32.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Float32Validation struct {
3131
Default float32
3232
TreatNullAsZero bool // `<field>: ` and `<field>: null` will be read as `<field>: 0.0`
3333
AllowedValues []float32
34+
HiddenAllowedValues []float32 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3435
DisallowedValues []float32
3536
CantBeSpecifiedErrStr *string
3637
GreaterThan *float32
@@ -207,7 +208,7 @@ func ValidateFloat32Val(val float32, v *Float32Validation) error {
207208
}
208209

209210
if len(v.AllowedValues) > 0 {
210-
if !slices.HasFloat32(v.AllowedValues, val) {
211+
if !slices.HasFloat32(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
211212
return ErrorInvalidFloat32(val, v.AllowedValues[0], v.AllowedValues[1:]...)
212213
}
213214
}

pkg/lib/configreader/float32_ptr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Float32PtrValidation struct {
2929
Default *float32
3030
AllowExplicitNull bool
3131
AllowedValues []float32
32+
HiddenAllowedValues []float32 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3233
DisallowedValues []float32
3334
CantBeSpecifiedErrStr *string
3435
GreaterThan *float32
@@ -41,6 +42,7 @@ type Float32PtrValidation struct {
4142
func makeFloat32ValValidation(v *Float32PtrValidation) *Float32Validation {
4243
return &Float32Validation{
4344
AllowedValues: v.AllowedValues,
45+
HiddenAllowedValues: v.HiddenAllowedValues,
4446
DisallowedValues: v.DisallowedValues,
4547
GreaterThan: v.GreaterThan,
4648
GreaterThanOrEqualTo: v.GreaterThanOrEqualTo,

pkg/lib/configreader/float64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Float64Validation struct {
3131
Default float64
3232
TreatNullAsZero bool // `<field>: ` and `<field>: null` will be read as `<field>: 0.0`
3333
AllowedValues []float64
34+
HiddenAllowedValues []float64 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3435
DisallowedValues []float64
3536
CantBeSpecifiedErrStr *string
3637
GreaterThan *float64
@@ -207,7 +208,7 @@ func ValidateFloat64Val(val float64, v *Float64Validation) error {
207208
}
208209

209210
if len(v.AllowedValues) > 0 {
210-
if !slices.HasFloat64(v.AllowedValues, val) {
211+
if !slices.HasFloat64(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
211212
return ErrorInvalidFloat64(val, v.AllowedValues[0], v.AllowedValues[1:]...)
212213
}
213214
}

pkg/lib/configreader/float64_ptr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Float64PtrValidation struct {
2929
Default *float64
3030
AllowExplicitNull bool
3131
AllowedValues []float64
32+
HiddenAllowedValues []float64 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3233
DisallowedValues []float64
3334
CantBeSpecifiedErrStr *string
3435
GreaterThan *float64
@@ -41,6 +42,7 @@ type Float64PtrValidation struct {
4142
func makeFloat64ValValidation(v *Float64PtrValidation) *Float64Validation {
4243
return &Float64Validation{
4344
AllowedValues: v.AllowedValues,
45+
HiddenAllowedValues: v.HiddenAllowedValues,
4446
DisallowedValues: v.DisallowedValues,
4547
GreaterThan: v.GreaterThan,
4648
GreaterThanOrEqualTo: v.GreaterThanOrEqualTo,

pkg/lib/configreader/int.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type IntValidation struct {
3131
Default int
3232
TreatNullAsZero bool // `<field>: ` and `<field>: null` will be read as `<field>: 0`
3333
AllowedValues []int
34+
HiddenAllowedValues []int // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3435
DisallowedValues []int
3536
CantBeSpecifiedErrStr *string
3637
GreaterThan *int
@@ -207,7 +208,7 @@ func ValidateIntVal(val int, v *IntValidation) error {
207208
}
208209

209210
if len(v.AllowedValues) > 0 {
210-
if !slices.HasInt(v.AllowedValues, val) {
211+
if !slices.HasInt(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
211212
return ErrorInvalidInt(val, v.AllowedValues[0], v.AllowedValues[1:]...)
212213
}
213214
}

pkg/lib/configreader/int32.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Int32Validation struct {
3131
Default int32
3232
TreatNullAsZero bool // `<field>: ` and `<field>: null` will be read as `<field>: 0`
3333
AllowedValues []int32
34+
HiddenAllowedValues []int32 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3435
DisallowedValues []int32
3536
CantBeSpecifiedErrStr *string
3637
GreaterThan *int32
@@ -207,7 +208,7 @@ func ValidateInt32Val(val int32, v *Int32Validation) error {
207208
}
208209

209210
if len(v.AllowedValues) > 0 {
210-
if !slices.HasInt32(v.AllowedValues, val) {
211+
if !slices.HasInt32(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
211212
return ErrorInvalidInt32(val, v.AllowedValues[0], v.AllowedValues[1:]...)
212213
}
213214
}

pkg/lib/configreader/int32_ptr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Int32PtrValidation struct {
2929
Default *int32
3030
AllowExplicitNull bool
3131
AllowedValues []int32
32+
HiddenAllowedValues []int32 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3233
DisallowedValues []int32
3334
CantBeSpecifiedErrStr *string
3435
GreaterThan *int32
@@ -41,6 +42,7 @@ type Int32PtrValidation struct {
4142
func makeInt32ValValidation(v *Int32PtrValidation) *Int32Validation {
4243
return &Int32Validation{
4344
AllowedValues: v.AllowedValues,
45+
HiddenAllowedValues: v.HiddenAllowedValues,
4446
DisallowedValues: v.DisallowedValues,
4547
GreaterThan: v.GreaterThan,
4648
GreaterThanOrEqualTo: v.GreaterThanOrEqualTo,

pkg/lib/configreader/int64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Int64Validation struct {
3131
Default int64
3232
TreatNullAsZero bool // `<field>: ` and `<field>: null` will be read as `<field>: 0`
3333
AllowedValues []int64
34+
HiddenAllowedValues []int64 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3435
DisallowedValues []int64
3536
CantBeSpecifiedErrStr *string
3637
GreaterThan *int64
@@ -207,7 +208,7 @@ func ValidateInt64Val(val int64, v *Int64Validation) error {
207208
}
208209

209210
if len(v.AllowedValues) > 0 {
210-
if !slices.HasInt64(v.AllowedValues, val) {
211+
if !slices.HasInt64(append(v.AllowedValues, v.HiddenAllowedValues...), val) {
211212
return ErrorInvalidInt64(val, v.AllowedValues[0], v.AllowedValues[1:]...)
212213
}
213214
}

pkg/lib/configreader/int64_ptr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Int64PtrValidation struct {
2929
Default *int64
3030
AllowExplicitNull bool
3131
AllowedValues []int64
32+
HiddenAllowedValues []int64 // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3233
DisallowedValues []int64
3334
CantBeSpecifiedErrStr *string
3435
GreaterThan *int64
@@ -41,6 +42,7 @@ type Int64PtrValidation struct {
4142
func makeInt64ValValidation(v *Int64PtrValidation) *Int64Validation {
4243
return &Int64Validation{
4344
AllowedValues: v.AllowedValues,
45+
HiddenAllowedValues: v.HiddenAllowedValues,
4446
DisallowedValues: v.DisallowedValues,
4547
GreaterThan: v.GreaterThan,
4648
GreaterThanOrEqualTo: v.GreaterThanOrEqualTo,

pkg/lib/configreader/int_ptr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type IntPtrValidation struct {
2929
Default *int
3030
AllowExplicitNull bool
3131
AllowedValues []int
32+
HiddenAllowedValues []int // allowed, but will not be listed as valid values (must be used in conjunction with AllowedValues)
3233
DisallowedValues []int
3334
CantBeSpecifiedErrStr *string
3435
GreaterThan *int
@@ -41,6 +42,7 @@ type IntPtrValidation struct {
4142
func makeIntValValidation(v *IntPtrValidation) *IntValidation {
4243
return &IntValidation{
4344
AllowedValues: v.AllowedValues,
45+
HiddenAllowedValues: v.HiddenAllowedValues,
4446
DisallowedValues: v.DisallowedValues,
4547
GreaterThan: v.GreaterThan,
4648
GreaterThanOrEqualTo: v.GreaterThanOrEqualTo,

0 commit comments

Comments
 (0)