From eb14f8319bdc0b705af9cb2f6dffb804ed5a29da Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 29 Jan 2021 09:15:10 -0500 Subject: [PATCH] Use UndefinedVariable Use UndefinedVariable to avoid the overloading usage of Unknown in the library. --- eval_context.go | 4 ++-- traversal.go | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/eval_context.go b/eval_context.go index e0822b7b..945f6ecf 100644 --- a/eval_context.go +++ b/eval_context.go @@ -12,9 +12,9 @@ type EvalContext struct { Functions map[string]function.Function parent *EvalContext - // UnknownVariable handles when an unknown variable is referenced. + // UndefinedVariable is called when an undefined variable is referenced. // This handler is experimental and may change in the future. - UnknownVariable func(Traversal) (cty.Value, error) + UndefinedVariable func(Traversal) (cty.Value, Diagnostics) } // NewChild returns a new EvalContext that is a child of the receiver. diff --git a/traversal.go b/traversal.go index cd66be59..2b579a41 100644 --- a/traversal.go +++ b/traversal.go @@ -70,10 +70,10 @@ func (t Traversal) TraverseAbs(ctx *EvalContext) (cty.Value, Diagnostics) { thisCtx := ctx hasNonNil := false - var unknownHandler func(Traversal) (cty.Value, error) + var undefinedHandler func(Traversal) (cty.Value, Diagnostics) for thisCtx != nil { - if unknownHandler == nil && thisCtx.UnknownVariable != nil { - unknownHandler = thisCtx.UnknownVariable + if undefinedHandler == nil && thisCtx.UndefinedVariable != nil { + undefinedHandler = thisCtx.UndefinedVariable } if thisCtx.Variables == nil { @@ -88,11 +88,9 @@ func (t Traversal) TraverseAbs(ctx *EvalContext) (cty.Value, Diagnostics) { thisCtx = thisCtx.parent } - if unknownHandler != nil { - v, err := unknownHandler(t) - if err == nil { - return v, nil - } + if undefinedHandler != nil { + v, diags := undefinedHandler(t) + return v, diags } if !hasNonNil {