Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 0f4f173

Browse files
committed
Only handle one panic we're interested in
else, "rethrow" so users can use functions that `panic` and have them act the way they're expecting.
1 parent ac9bf72 commit 0f4f173

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

gomock/call.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,23 @@ func (c *Call) Do(f interface{}) *Call {
153153
}
154154
}
155155
defer func() {
156-
if err := recover(); err != nil {
156+
if r := recover(); r != nil {
157+
errMsg, ok := r.(string)
158+
159+
// We only handle a very specific panic
160+
// If it's not that one, then we "rethrow" the panic
161+
// This allows users to use functions that panic in their tests
162+
if !ok {
163+
panic(r)
164+
}
165+
if !strings.Contains(errMsg, "reflect: Call using") {
166+
panic(r)
167+
}
157168
skipFrames := 8
158169
stackTraceStr := "\n\n" + currentStackTrace(skipFrames)
159170
funcPC := v.Pointer()
160171
file, line := runtime.FuncForPC(funcPC).FileLine(funcPC)
161-
c.t.Fatalf("%s (incorrect func args at %s:%d?)%+v", err, file, line, stackTraceStr)
172+
c.t.Fatalf("%s (incorrect func args at %s:%d?)%+v", errMsg, file, line, stackTraceStr)
162173
}
163174
}()
164175
v.Call(vargs)

0 commit comments

Comments
 (0)