Skip to content

Commit

Permalink
Merge pull request #3 from housinganywhere/add-logging-on-errors
Browse files Browse the repository at this point in the history
add logging on errors to improve debugging
  • Loading branch information
slockij authored Mar 7, 2017
2 parents ad7f67b + c3a3f4d commit d69ed02
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"reflect"
"runtime/debug"
"strings"

"github.com/housinganywhere/graphql/gqlerrors"
Expand Down Expand Up @@ -44,6 +45,8 @@ func Execute(p ExecuteParams) (result *Result) {

defer func() {
if r := recover(); r != nil {
fmt.Println("ERROR caught in graphql (Executor):", r)
fmt.Println(string(debug.Stack()))
var err error
if r, ok := r.(error); ok {
err = gqlerrors.FormatError(r)
Expand Down Expand Up @@ -480,6 +483,8 @@ func resolveField(eCtx *ExecutionContext, parentType *Object, source interface{}
var returnType Output
defer func() (interface{}, resolveFieldResultState) {
if r := recover(); r != nil {
fmt.Println("ERROR caught in graphql (resolveField):", r)
fmt.Println(string(debug.Stack()))

var err error
if r, ok := r.(string); ok {
Expand Down Expand Up @@ -556,6 +561,8 @@ func completeValueCatchingError(eCtx *ExecutionContext, returnType Type, fieldAS
// catch panic
defer func() interface{} {
if r := recover(); r != nil {
fmt.Println("ERROR caught in graphql (completeValueCatchingError):", r)
fmt.Println(string(debug.Stack()))
//send panic upstream
if _, ok := returnType.(*NonNull); ok {
panic(r)
Expand Down

0 comments on commit d69ed02

Please sign in to comment.