diff --git a/context.go b/context.go index c41c71ecf9..ef822cc72b 100644 --- a/context.go +++ b/context.go @@ -922,7 +922,10 @@ func (c *Context) Render(code int, r render.Render) { } if err := r.Render(c.Writer); err != nil { - panic(err) + panic(Error{ + Err: err, + Type: ErrorTypeRender, + }) } } diff --git a/context_test.go b/context_test.go index 85e0a6161e..16ac5508b0 100644 --- a/context_test.go +++ b/context_test.go @@ -655,6 +655,16 @@ func TestContextRenderPanicIfErr(t *testing.T) { defer func() { r := recover() assert.Equal(t, "TestPanicRender", fmt.Sprint(r)) + + // confirm the recovered object is an error + err, ok := r.(error) + assert.True(t, ok) + + // the error returned should be a gin render Error + e := Error{} + assert.True(t, errors.As(err, &e)) + assert.ErrorContains(t, e.Unwrap(), "TestPanicRender") + assert.True(t, e.IsType(ErrorTypeRender)) }() w := httptest.NewRecorder() c, _ := CreateTestContext(w)