diff --git a/terraform/graph.go b/terraform/graph.go index 38b65edea..717745b12 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -3,7 +3,6 @@ package terraform import ( "fmt" "log" - "runtime/debug" "github.com/hashicorp/terraform/tfdiags" @@ -47,12 +46,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { // Get the path for logs path := ctx.Path().String() - // Determine if our walker is a panic wrapper - panicwrap, ok := walker.(GraphWalkerPanicwrapper) - if !ok { - panicwrap = nil // just to be sure - } - debugName := "walk-graph.json" if g.debugName != "" { debugName = g.debugName + "-" + debugName @@ -68,28 +61,8 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics { log.Printf("[TRACE] vertex %q: starting visit (%T)", dag.VertexName(v), v) g.DebugVisitInfo(v, g.debugName) - // If we have a panic wrap GraphWalker and a panic occurs, recover - // and call that. We ensure the return value is an error, however, - // so that future nodes are not called. defer func() { log.Printf("[TRACE] vertex %q: visit complete", dag.VertexName(v)) - - // If no panicwrap, do nothing - if panicwrap == nil { - return - } - - // If no panic, do nothing - err := recover() - if err == nil { - return - } - - // Modify the return value to show the error - diags = diags.Append(fmt.Errorf("vertex %q captured panic: %s\n\n%s", dag.VertexName(v), err, debug.Stack())) - - // Call the panic wrapper - panicwrap.Panic(v, err) }() walker.EnterVertex(v) diff --git a/terraform/graph_test.go b/terraform/graph_test.go index db4ddc403..91f5774de 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -6,23 +6,6 @@ import ( "github.com/hashicorp/terraform/dag" ) -func TestGraphWalk_panicWrap(t *testing.T) { - var g Graph - - // Add our crasher - v := &testGraphSubPath{ - PathFn: func() []string { - panic("yo") - }, - } - g.Add(v) - - err := g.Walk(GraphWalkerPanicwrap(new(NullGraphWalker))) - if err == nil { - t.Fatal("should error") - } -} - // testGraphContains is an assertion helper that tests that a node is // contained in the graph. func testGraphContains(t *testing.T, g *Graph, name string) { diff --git a/terraform/graph_walk.go b/terraform/graph_walk.go index 13178a09d..e980e0c6d 100644 --- a/terraform/graph_walk.go +++ b/terraform/graph_walk.go @@ -17,36 +17,6 @@ type GraphWalker interface { ExitEvalTree(dag.Vertex, interface{}, error) tfdiags.Diagnostics } -// GrpahWalkerPanicwrapper can be optionally implemented to catch panics -// that occur while walking the graph. This is not generally recommended -// since panics should crash Terraform and result in a bug report. However, -// this is particularly useful for situations like the shadow graph where -// you don't ever want to cause a panic. -type GraphWalkerPanicwrapper interface { - GraphWalker - - // Panic is called when a panic occurs. This will halt the panic from - // propogating so if the walker wants it to crash still it should panic - // again. This is called from within a defer so runtime/debug.Stack can - // be used to get the stack trace of the panic. - Panic(dag.Vertex, interface{}) -} - -// GraphWalkerPanicwrap wraps an existing Graphwalker to wrap and swallow -// the panics. This doesn't lose the panics since the panics are still -// returned as errors as part of a graph walk. -func GraphWalkerPanicwrap(w GraphWalker) GraphWalkerPanicwrapper { - return &graphWalkerPanicwrapper{ - GraphWalker: w, - } -} - -type graphWalkerPanicwrapper struct { - GraphWalker -} - -func (graphWalkerPanicwrapper) Panic(dag.Vertex, interface{}) {} - // NullGraphWalker is a GraphWalker implementation that does nothing. // This can be embedded within other GraphWalker implementations for easily // implementing all the required functions.