lang: Fix non-string key panics in map function#24277
Conversation
Codecov Report
@@ Coverage Diff @@
## master #24277 +/- ##
==========================================
- Coverage 56.96% 56.95% -0.02%
==========================================
Files 656 656
Lines 59223 59225 +2
==========================================
- Hits 33737 33730 -7
- Misses 22471 22483 +12
+ Partials 3015 3012 -3
Continue to review full report at Codecov.
|
| return cty.NilVal, err | ||
| } | ||
| if keyVal.IsNull() { | ||
| return cty.NilVal, fmt.Errorf("argument %d is a null key", i+1) |
There was a problem hiding this comment.
Not super important here, but just wanted to point out that you can return the special error type ArgError from a function (e.g. using NewArgErrorf instead of Errorf here) to indicate that a specific argument is incorrect.
When using functions with HCL, HCL recognizes that error type and indicates the specific single argument as the problem, rather than the entire call.
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The map function assumed that the key arguments were strings, and would panic if they were not.
After this commit, calling
map(1, 2)will result in a map{"1" = 2}, and callingmap(null, 1)will result in a syntax error.Fixes #23346, fixes #23043