Skip to content

Commit 7e7f2e9

Browse files
committed
🐛 Be more helpful with floats when allowDangerousTypes=false
Currently, we fall through and just emit an error telling that floats are not supported which lead to ppl creating prs to add support. We actually do support them although that is discouraged. This change makes us emit a more helpful error.
1 parent 14c7780 commit 7e7f2e9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/crd/schema.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package crd
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"go/ast"
2223
"go/token"
@@ -427,10 +428,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
427428
typ = "string"
428429
case basicInfo&types.IsInteger != 0:
429430
typ = "integer"
430-
case basicInfo&types.IsFloat != 0 && allowDangerousTypes:
431-
typ = "number"
431+
case basicInfo&types.IsFloat != 0:
432+
if allowDangerousTypes {
433+
typ = "number"
434+
} else {
435+
return "", "", errors.New("found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true")
436+
}
432437
default:
433-
// NB(directxman12): floats are *NOT* allowed in kubernetes APIs
434438
return "", "", fmt.Errorf("unsupported type %q", basic.String())
435439
}
436440

0 commit comments

Comments
 (0)