MCPcopy
hub / github.com/hashicorp/hcl / decode

Method decode

hcldec/spec.go:1577–1601  ·  view source on GitHub ↗
(content *hcl.BodyContent, blockLabels []blockLabel, ctx *hcl.EvalContext)

Source from the content-addressed store, hash-verified

1575}
1576
1577func (s *TransformFuncSpec) decode(content *hcl.BodyContent, blockLabels []blockLabel, ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
1578 wrappedVal, diags := s.Wrapped.decode(content, blockLabels, ctx)
1579 if diags.HasErrors() {
1580 // We won't try to run our function in this case, because it'll probably
1581 // generate confusing additional errors that will distract from the
1582 // root cause.
1583 return cty.UnknownVal(s.impliedType().WithoutOptionalAttributesDeep()), diags
1584 }
1585
1586 resultVal, err := s.Func.Call([]cty.Value{wrappedVal})
1587 if err != nil {
1588 // This is not a good example of a diagnostic because it is reporting
1589 // a programming error in the calling application, rather than something
1590 // an end-user could act on.
1591 diags = append(diags, &hcl.Diagnostic{
1592 Severity: hcl.DiagError,
1593 Summary: "Transform function failed",
1594 Detail: fmt.Sprintf("Decoder transform returned an error: %s", err),
1595 Subject: s.sourceRange(content, blockLabels).Ptr(),
1596 })
1597 return cty.UnknownVal(s.impliedType().WithoutOptionalAttributesDeep()), diags
1598 }
1599
1600 return resultVal, diags
1601}
1602
1603func (s *TransformFuncSpec) impliedType() cty.Type {
1604 wrappedTy := s.Wrapped.impliedType()

Callers

nothing calls this directly

Calls 5

impliedTypeMethod · 0.95
sourceRangeMethod · 0.95
HasErrorsMethod · 0.80
PtrMethod · 0.80
decodeMethod · 0.65

Tested by

no test coverage detected