handle wrapped EvalEarlyExitErrors

This commit is contained in:
James Bardin 2020-10-28 10:59:32 -04:00
parent 477111e6b6
commit fe9c93b9f9

View File

@ -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
}