1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
13 // PanicFilter wraps the action invocation in a protective defer blanket that
14 // converts panics into 500 error pages.
15 func PanicFilter(c *Controller, fc []Filter) {
17 if err := recover(); err != nil {
18 handleInvocationPanic(c, err)
24 // This function handles a panic in an action invocation.
25 // It cleans up the stack trace, logs it, and displays an error page.
26 func handleInvocationPanic(c *Controller, err interface{}) {
27 error := NewErrorFromPanic(err)
29 utilLog.Error("PanicFilter: Caught panic", "error", err, "stack", error.Stack)
32 fmt.Println(error.Stack)
35 utilLog.Error("PanicFilter: Caught panic, unable to determine stack location", "error", err, "stack", string(debug.Stack()))
38 fmt.Println("stack", string(debug.Stack()))
42 if error == nil && DevMode {
43 // Only show the sensitive information in the debug stack trace in development mode, not production
44 c.Response.SetStatus(http.StatusInternalServerError)
45 _, _ = c.Response.GetWriter().Write(debug.Stack())
49 c.Result = c.RenderError(error)