summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMartin Atkins <mart@degeneration.co.uk>2018-07-28 13:14:36 -0700
committerMartin Atkins <mart@degeneration.co.uk>2018-07-28 13:14:36 -0700
commit93562f805f4038bfab54bb3ae518c87aeb116253 (patch)
treefea5d1a192dbbd59ffa25af45b87f47d8d9fb885 /ext
parent41cff854d8157be197e6b4698a8d9570ced9476b (diff)
hcl: Annotate diagnostics with expression EvalContext
When we're evaluating expressions, we may end up evaluating the same source-level expression a number of times in different contexts, such as in a 'for' expression, where each one may produce a different set of diagnostic messages. Now we'll attach the EvalContext to each expression diagnostic so that a diagnostic renderer can potentially show additional information to help distinguish the different iterations in rendered diagnostics.
Diffstat (limited to 'ext')
-rw-r--r--ext/dynblock/expand_spec.go45
1 files changed, 25 insertions, 20 deletions
diff --git a/ext/dynblock/expand_spec.go b/ext/dynblock/expand_spec.go
index fa91c9f..a0734f6 100644
--- a/ext/dynblock/expand_spec.go
+++ b/ext/dynblock/expand_spec.go
@@ -43,19 +43,21 @@ func (b *expandBody) decodeSpec(blockS *hcl.BlockHeaderSchema, rawSpec *hcl.Bloc
if !eachVal.CanIterateElements() {
diags = append(diags, &hcl.Diagnostic{
- Severity: hcl.DiagError,
- Summary: "Invalid dynamic for_each value",
- Detail: fmt.Sprintf("Cannot use a value of type %s in for_each. An iterable collection is required.", eachVal.Type()),
- Subject: eachAttr.Expr.Range().Ptr(),
+ Severity: hcl.DiagError,
+ Summary: "Invalid dynamic for_each value",
+ Detail: fmt.Sprintf("Cannot use a value of type %s in for_each. An iterable collection is required.", eachVal.Type()),
+ Subject: eachAttr.Expr.Range().Ptr(),
+ EvalContext: b.forEachCtx,
})
return nil, diags
}
if eachVal.IsNull() {
diags = append(diags, &hcl.Diagnostic{
- Severity: hcl.DiagError,
- Summary: "Invalid dynamic for_each value",
- Detail: "Cannot use a null value in for_each.",
- Subject: eachAttr.Expr.Range().Ptr(),
+ Severity: hcl.DiagError,
+ Summary: "Invalid dynamic for_each value",
+ Detail: "Cannot use a null value in for_each.",
+ Subject: eachAttr.Expr.Range().Ptr(),
+ EvalContext: b.forEachCtx,
})
return nil, diags
}
@@ -159,28 +161,31 @@ func (s *expandSpec) newBlock(i *iteration, ctx *hcl.EvalContext) (*hcl.Block, h
labelVal, convErr = convert.Convert(labelVal, cty.String)
if convErr != nil {
diags = append(diags, &hcl.Diagnostic{
- Severity: hcl.DiagError,
- Summary: "Invalid dynamic block label",
- Detail: fmt.Sprintf("Cannot use this value as a dynamic block label: %s.", convErr),
- Subject: labelExpr.Range().Ptr(),
+ Severity: hcl.DiagError,
+ Summary: "Invalid dynamic block label",
+ Detail: fmt.Sprintf("Cannot use this value as a dynamic block label: %s.", convErr),
+ Subject: labelExpr.Range().Ptr(),
+ EvalContext: lCtx,
})
return nil, diags
}
if labelVal.IsNull() {
diags = append(diags, &hcl.Diagnostic{
- Severity: hcl.DiagError,
- Summary: "Invalid dynamic block label",
- Detail: "Cannot use a null value as a dynamic block label.",
- Subject: labelExpr.Range().Ptr(),
+ Severity: hcl.DiagError,
+ Summary: "Invalid dynamic block label",
+ Detail: "Cannot use a null value as a dynamic block label.",
+ Subject: labelExpr.Range().Ptr(),
+ EvalContext: lCtx,
})
return nil, diags
}
if !labelVal.IsKnown() {
diags = append(diags, &hcl.Diagnostic{
- Severity: hcl.DiagError,
- Summary: "Invalid dynamic block label",
- Detail: "This value is not yet known. Dynamic block labels must be immediately-known values.",
- Subject: labelExpr.Range().Ptr(),
+ Severity: hcl.DiagError,
+ Summary: "Invalid dynamic block label",
+ Detail: "This value is not yet known. Dynamic block labels must be immediately-known values.",
+ Subject: labelExpr.Range().Ptr(),
+ EvalContext: lCtx,
})
return nil, diags
}