lang/funcs: Fix panic in "join" when an element is null

It is now a proper error message.
This commit is contained in:
Martin Atkins 2019-02-07 14:35:13 -08:00
parent c794bf5bcc
commit f8a6f66be4
1 changed files with 9 additions and 1 deletions

View File

@ -39,10 +39,18 @@ var JoinFunc = function.New(&function.Spec{
}
items := make([]string, 0, l)
for _, list := range listVals {
for ai, list := range listVals {
ei := 0
for it := list.ElementIterator(); it.Next(); {
_, val := it.Element()
if val.IsNull() {
if len(listVals) > 1 {
return cty.UnknownVal(cty.String), function.NewArgErrorf(ai+1, "element %d of list %d is null; cannot concatenate null values", ei, ai+1)
}
return cty.UnknownVal(cty.String), function.NewArgErrorf(ai+1, "element %d is null; cannot concatenate null values", ei)
}
items = append(items, val.AsString())
ei++
}
}