Skip to content

Commit

Permalink
Use UndefinedVariable
Browse files Browse the repository at this point in the history
Use UndefinedVariable to avoid the overloading usage of Unknown in the
library.
  • Loading branch information
Mahmood Ali committed Apr 7, 2021
1 parent ccf34c5 commit eb14f83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions eval_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 6 additions & 8 deletions traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit eb14f83

Please sign in to comment.