From fe9c93b9f957bbdb71c9906ea7f9635c7d9a51a6 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 28 Oct 2020 10:59:32 -0400 Subject: [PATCH] handle wrapped EvalEarlyExitErrors --- terraform/graph_walk_context.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/terraform/graph_walk_context.go b/terraform/graph_walk_context.go index 26ab193623..1c8273e977 100644 --- a/terraform/graph_walk_context.go +++ b/terraform/graph_walk_context.go @@ -2,6 +2,7 @@ package terraform import ( "context" + "errors" "sync" "github.com/zclconf/go-cty/cty" @@ -145,16 +146,34 @@ func (w *ContextGraphWalker) Execute(ctx EvalContext, n GraphNodeExecutable) tfd return nil } - if _, isEarlyExit := err.(EvalEarlyExitError); isEarlyExit { + var diags tfdiags.Diagnostics + + // Handle a simple early exit error + if errors.Is(err, EvalEarlyExitError{}) { return nil } + // we need to see if this wraps only EarlyExitErrors + if wrapper, ok := err.(interface{ WrappedErrors() []error }); ok { + //WrappedErrors only returns native error values, so we can't extract + //them from diagnostics. Just return the whole thing if we have a + //combination. + errs := wrapper.WrappedErrors() + earlyExit := true + for _, err := range errs { + if err != (EvalEarlyExitError{}) { + earlyExit = false + } + } + if len(errs) > 0 && earlyExit { + return nil + } + } + // Otherwise, we'll let our usual diagnostics machinery figure out how to // unpack this as one or more diagnostic messages and return that. If we // get down here then the returned diagnostics will contain at least one // error, causing the graph walk to halt. - var diags tfdiags.Diagnostics diags = diags.Append(err) return diags - }