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:
parent
8654cf0361
commit
cd019809a4
@ -156,7 +156,16 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *zcl.Range, labels
|
|||||||
diags = diags.Append(&zcl.Diagnostic{
|
diags = diags.Append(&zcl.Diagnostic{
|
||||||
Severity: zcl.DiagError,
|
Severity: zcl.DiagError,
|
||||||
Summary: "Incorrect JSON value type",
|
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(),
|
Subject: v.StartRange().Ptr(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user