diff options
| author | Martin Atkins <mart@degeneration.co.uk> | 2018-07-28 13:36:55 -0700 |
|---|---|---|
| committer | Martin Atkins <mart@degeneration.co.uk> | 2018-07-28 13:36:55 -0700 |
| commit | 6356254632430403c253659b6d12a6384ef2ec31 (patch) | |
| tree | 5ed8ce8238533b8e716eebcfbb85d8c740c4b6f2 /ext/dynblock/expand_spec.go | |
| parent | 956c336d402a438e8216c2836672349c6e03fd11 (diff) | |
hcl: Include Expression reference in diagnostics
If a diagnostic occurs while we're evaluating an expression, we'll now
include a reference to that expression in the diagnostic object. We
previously added the corresponding EvalContext here too, and so with these
together it is now possible for a diagnostic renderer to see not only
what was in scope when the problem occurred but also what parts of that
scope the expression was relying on (via method Expression.Variables).
Diffstat (limited to 'ext/dynblock/expand_spec.go')
| -rw-r--r-- | ext/dynblock/expand_spec.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/ext/dynblock/expand_spec.go b/ext/dynblock/expand_spec.go index a0734f6..be76cd0 100644 --- a/ext/dynblock/expand_spec.go +++ b/ext/dynblock/expand_spec.go @@ -47,6 +47,7 @@ func (b *expandBody) decodeSpec(blockS *hcl.BlockHeaderSchema, rawSpec *hcl.Bloc 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(), + Expression: eachAttr.Expr, EvalContext: b.forEachCtx, }) return nil, diags @@ -57,6 +58,7 @@ func (b *expandBody) decodeSpec(blockS *hcl.BlockHeaderSchema, rawSpec *hcl.Bloc Summary: "Invalid dynamic for_each value", Detail: "Cannot use a null value in for_each.", Subject: eachAttr.Expr.Range().Ptr(), + Expression: eachAttr.Expr, EvalContext: b.forEachCtx, }) return nil, diags @@ -165,6 +167,7 @@ func (s *expandSpec) newBlock(i *iteration, ctx *hcl.EvalContext) (*hcl.Block, h Summary: "Invalid dynamic block label", Detail: fmt.Sprintf("Cannot use this value as a dynamic block label: %s.", convErr), Subject: labelExpr.Range().Ptr(), + Expression: labelExpr, EvalContext: lCtx, }) return nil, diags @@ -175,6 +178,7 @@ func (s *expandSpec) newBlock(i *iteration, ctx *hcl.EvalContext) (*hcl.Block, h Summary: "Invalid dynamic block label", Detail: "Cannot use a null value as a dynamic block label.", Subject: labelExpr.Range().Ptr(), + Expression: labelExpr, EvalContext: lCtx, }) return nil, diags @@ -185,6 +189,7 @@ func (s *expandSpec) newBlock(i *iteration, ctx *hcl.EvalContext) (*hcl.Block, h Summary: "Invalid dynamic block label", Detail: "This value is not yet known. Dynamic block labels must be immediately-known values.", Subject: labelExpr.Range().Ptr(), + Expression: labelExpr, EvalContext: lCtx, }) return nil, diags |
