Replies: 1 comment
|
cty's convert function takes a type constraint expression, and current Buildx registers HCL's type-aware ConvertFunc. The error shown came from an older Buildx/Bake parser that treated list(string) as an ordinary call to an undefined function named list. More importantly, a cty list is homogeneous before your function runs. A caller cannot pass [3, "4.0"] as one list and defer normalization to convert. Let HCL coerce the list at its boundary, or normalize values individually as strings. The first fix is therefore to update Buildx. On a current release this is valid: If you need compatibility with the old version, make the function contract a list of strings instead: Call it with string versions: If callers have numeric values, normalize them when declaring/calling the function (for example use quoted versions or format("%v", value) where appropriate). A cty list is homogeneous, so a truly mixed list is not a useful input contract even after upgrading. You can inspect the current registration in bake/hclparser/stdlib.go, which uses typeexpr.ConvertFunc. The current generated stdlib docs also show convert("42", number). Thus, on current Buildx list(string) and bool are type expressions specifically inside convert; they are not standalone runtime functions. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Not sure whether that's a problem with me or a bug but here is what I'm trying to do:
I wrote a function in my bake file to compute a list of targets based on an whether an env var (
MY_ VERSION) matches a list ofversions:As you can see above, I'd like to deal with cases where someone using that function passes numbers (e.g.
[3, 4]) or string representation of the version (["3.0", "4.0"]) in theversionslist.Though when running that simple code I get the error below:
I've tried with more simple types and get the same error (e.g.
convert("true", bool))I would have expected that to work given the bake Reference states:
All reactions