mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
798adf3ce6
An earlier commit today reworked this to handle non-fatal errors, which are returned "smuggled" as a special type of error to avoid changing the EvalNode interface. Unfortunately, that change then broke the _other_ special thing we smuggle through the error return path: early exit. Now we'll handle them both. This is not perfect because the early-exit path causes us to discard any warnings we've already collected, but it's more important that we bail early than retain warnings.
43 lines
888 B
Go
43 lines
888 B
Go
package terraform
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
)
|
|
|
|
// EvalSequence is an EvalNode that evaluates in sequence.
|
|
type EvalSequence struct {
|
|
Nodes []EvalNode
|
|
}
|
|
|
|
func (n *EvalSequence) Eval(ctx EvalContext) (interface{}, error) {
|
|
var diags tfdiags.Diagnostics
|
|
|
|
for _, n := range n.Nodes {
|
|
if n == nil {
|
|
continue
|
|
}
|
|
|
|
if _, err := EvalRaw(n, ctx); err != nil {
|
|
if _, isEarlyExit := err.(EvalEarlyExitError); isEarlyExit {
|
|
// In this path we abort early, losing any non-error
|
|
// diagnostics we saw earlier.
|
|
return nil, err
|
|
}
|
|
diags = diags.Append(err)
|
|
if diags.HasErrors() {
|
|
// Halt if we get some errors, but warnings are okay.
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, diags.ErrWithWarnings()
|
|
}
|
|
|
|
// EvalNodeFilterable impl.
|
|
func (n *EvalSequence) Filter(fn EvalNodeFilterFunc) {
|
|
for i, node := range n.Nodes {
|
|
n.Nodes[i] = fn(node)
|
|
}
|
|
}
|