Report panic context for SingletonContext.VisitAllModules

If a panic occurs in SingletonContext.VisitAllModules report the
module that was being visited.

Change-Id: Ia7fc07e2e33e9e3c0297903d3b06b7efb33f0105
This commit is contained in:
Colin Cross 2018-09-19 13:37:29 -07:00
parent 0799fad550
commit 7f90d170b3

View file

@ -212,7 +212,18 @@ func (s *singletonContext) AddSubninja(file string) {
}
func (s *singletonContext) VisitAllModules(visit func(Module)) {
s.context.VisitAllModules(visit)
var visitingModule Module
defer func() {
if r := recover(); r != nil {
panic(newPanicErrorf(r, "VisitAllModules(%s) for module %s",
funcName(visit), visitingModule))
}
}()
s.context.VisitAllModules(func(m Module) {
visitingModule = m
visit(m)
})
}
func (s *singletonContext) VisitAllModulesIf(pred func(Module) bool,