diff --git a/pkg/api/errors/errors_test.go b/pkg/api/errors/errors_test.go index e4743d0d7..2dea0883a 100644 --- a/pkg/api/errors/errors_test.go +++ b/pkg/api/errors/errors_test.go @@ -164,7 +164,7 @@ func TestNewInvalid(t *testing.T) { `Kind "name" is invalid: field[0].name: Not found: "bar"`, }, { - field.NotSupported(field.NewPath("field[0].name"), "bar", nil), + field.NotSupported[string](field.NewPath("field[0].name"), "bar", nil), &metav1.StatusDetails{ Kind: "Kind", Name: "name", diff --git a/pkg/util/validation/field/errors.go b/pkg/util/validation/field/errors.go index ae73bda96..bc387d011 100644 --- a/pkg/util/validation/field/errors.go +++ b/pkg/util/validation/field/errors.go @@ -200,12 +200,12 @@ func Invalid(field *Path, value interface{}, detail string) *Error { // NotSupported returns a *Error indicating "unsupported value". // This is used to report unknown values for enumerated fields (e.g. a list of // valid values). -func NotSupported(field *Path, value interface{}, validValues []string) *Error { +func NotSupported[T ~string](field *Path, value interface{}, validValues []T) *Error { detail := "" if len(validValues) > 0 { quotedValues := make([]string, len(validValues)) for i, v := range validValues { - quotedValues[i] = strconv.Quote(v) + quotedValues[i] = strconv.Quote(fmt.Sprint(v)) } detail = "supported values: " + strings.Join(quotedValues, ", ") } diff --git a/pkg/util/validation/field/errors_test.go b/pkg/util/validation/field/errors_test.go index fe747319b..a2f9763b8 100644 --- a/pkg/util/validation/field/errors_test.go +++ b/pkg/util/validation/field/errors_test.go @@ -32,7 +32,7 @@ func TestMakeFuncs(t *testing.T) { ErrorTypeInvalid, }, { - func() *Error { return NotSupported(NewPath("f"), "v", nil) }, + func() *Error { return NotSupported[string](NewPath("f"), "v", nil) }, ErrorTypeNotSupported, }, {