@@ -15,12 +15,42 @@ type GraphWalker interface {
1515 ExitEvalTree (dag.Vertex , interface {}, error ) error
1616}
1717
18+ // GrpahWalkerPanicwrapper can be optionally implemented to catch panics
19+ // that occur while walking the graph. This is not generally recommended
20+ // since panics should crash Terraform and result in a bug report. However,
21+ // this is particularly useful for situations like the shadow graph where
22+ // you don't ever want to cause a panic.
23+ type GraphWalkerPanicwrapper interface {
24+ GraphWalker
25+
26+ // Panic is called when a panic occurs. This will halt the panic from
27+ // propogating so if the walker wants it to crash still it should panic
28+ // again. This is called from within a defer so runtime/debug.Stack can
29+ // be used to get the stack trace of the panic.
30+ Panic (dag.Vertex , interface {})
31+ }
32+
33+ // GraphWalkerPanicwrap wraps an existing Graphwalker to wrap and swallow
34+ // the panics. This doesn't lose the panics since the panics are still
35+ // returned as errors as part of a graph walk.
36+ func GraphWalkerPanicwrap (w GraphWalker ) GraphWalkerPanicwrapper {
37+ return & graphWalkerPanicwrapper {
38+ GraphWalker : w ,
39+ }
40+ }
41+
42+ type graphWalkerPanicwrapper struct {
43+ GraphWalker
44+ }
45+
46+ func (graphWalkerPanicwrapper ) Panic (dag.Vertex , interface {}) {}
47+
1848// NullGraphWalker is a GraphWalker implementation that does nothing.
1949// This can be embedded within other GraphWalker implementations for easily
2050// implementing all the required functions.
2151type NullGraphWalker struct {}
2252
23- func (NullGraphWalker ) EnterPath ([]string ) EvalContext { return nil }
53+ func (NullGraphWalker ) EnterPath ([]string ) EvalContext { return new ( MockEvalContext ) }
2454func (NullGraphWalker ) ExitPath ([]string ) {}
2555func (NullGraphWalker ) EnterVertex (dag.Vertex ) {}
2656func (NullGraphWalker ) ExitVertex (dag.Vertex , error ) {}
0 commit comments