Skip to content

Commit 301f3e2

Browse files
committedDec 14, 2022
GinkgoRecover now supports ignoring panics that match a specific, hidden, interface
1 parent 60240d1 commit 301f3e2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
 

Diff for: ‎core_dsl.go

+9
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ func AbortSuite(message string, callerSkip ...int) {
369369
panic(types.GinkgoErrors.UncaughtGinkgoPanic(cl))
370370
}
371371

372+
/*
373+
ignorablePanic is used by Gomega to signal to GinkgoRecover that Goemga is handling
374+
the error associated with this panic. It i used when Eventually/Consistently are passed a func(g Gomega) and the resulting function launches a goroutines that makes a failed assertion. That failed assertion is registered by Gomega and then panics. Ordinarily the panic is captured by Gomega. In the case of a goroutine Gomega can't capture the panic - so we piggy back on GinkgoRecover so users have a single defer GinkgoRecover() pattern to follow. To do that we need to tell Ginkgo to ignore this panic and not register it as a panic on the global Failer.
375+
*/
376+
type ignorablePanic interface{ GinkgoRecoverShouldIgnoreThisPanic() }
377+
372378
/*
373379
GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail`
374380
Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that
@@ -384,6 +390,9 @@ You can learn more about how Ginkgo manages failures here: https://onsi.github.i
384390
func GinkgoRecover() {
385391
e := recover()
386392
if e != nil {
393+
if _, ok := e.(ignorablePanic); ok {
394+
return
395+
}
387396
global.Failer.Panic(types.NewCodeLocationWithStackTrace(1), e)
388397
}
389398
}

0 commit comments

Comments
 (0)
Please sign in to comment.