MCPcopy
hub / github.com/dgraph-io/dgraph / PanicHandler

Function PanicHandler

graphql/api/panics.go:20–29  ·  view source on GitHub ↗

PanicHandler catches panics to make sure that we recover from panics during GraphQL request execution and return an appropriate error. If PanicHandler recovers from a panic, it logs a stack trace, creates an error and applies fn to the error.

(fn func(error), query string)

Source from the content-addressed store, hash-verified

18// If PanicHandler recovers from a panic, it logs a stack trace, creates an error
19// and applies fn to the error.
20func PanicHandler(fn func(error), query string) {
21 if err := recover(); err != nil {
22 // Log the panic along with query which caused it.
23 glog.Errorf("panic: %s.\n query: %s\n trace: %s", err, query, string(debug.Stack()))
24
25 fn(errors.Errorf("Internal Server Error - a panic was trapped. " +
26 "This indicates a bug in the GraphQL server. A stack trace was logged. " +
27 "Please let us know by filing an issue with the stack trace."))
28 }
29}

Callers 2

ResolveMethod · 0.92
recoveryHandlerFunction · 0.92

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected