hcl: When rendering diagnostics, elide complex index keys

In practice this should never arise because the index operator only works
for lists and maps and they use string keys, but we'll guard against this
anyway and return a placeholder for other values so that the output
doesn't grow unreadably long in that case.
This commit is contained in:
Martin Atkins 2018-07-28 14:51:11 -07:00
parent f45c1cdace
commit 5919f80710
1 changed files with 7 additions and 1 deletions

View File

@ -225,7 +225,13 @@ func (w *diagnosticTextWriter) traversalStr(traversal Traversal) string {
buf.WriteString(tStep.Name)
case TraverseIndex:
buf.WriteByte('[')
buf.WriteString(w.valueStr(tStep.Key))
if keyTy := tStep.Key.Type(); keyTy.IsPrimitiveType() {
buf.WriteString(w.valueStr(tStep.Key))
} else {
// We'll just use a placeholder for more complex values,
// since otherwise our result could grow ridiculously long.
buf.WriteString("...")
}
buf.WriteByte(']')
}
}