json: detect and report insufficient object levels for block labels

When decoding a block with labels, the right number of object levels must
be present to populate the labels.
This commit is contained in:
Martin Atkins 2017-05-21 12:42:42 -07:00
parent 8654cf0361
commit cd019809a4

View File

@ -156,7 +156,16 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *zcl.Range, labels
diags = diags.Append(&zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Incorrect JSON value type",
Detail: fmt.Sprintf("A JSON object is required, whose keys represent the %q block's %s.", typeName, labelName),
Detail: fmt.Sprintf("A JSON object is required, whose keys represent the %s block's %s.", typeName, labelName),
Subject: v.StartRange().Ptr(),
})
return
}
if len(ov.Attrs) == 0 {
diags = diags.Append(&zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Missing block label",
Detail: fmt.Sprintf("At least one object property is required, whose name represents the %s block's %s.", typeName, labelName),
Subject: v.StartRange().Ptr(),
})
return