Skip to content

Commit

Permalink
Add context to recover func
Browse files Browse the repository at this point in the history
This makes the request and resolver contexts available during panic
so that you can log the incoming query, user info etc with your bug
tracker
  • Loading branch information
Adam Scarr committed Apr 23, 2018
1 parent 3ceaa18 commit d157ac3
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion codegen/templates/data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/templates/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
2 changes: 1 addition & 1 deletion example/chat/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
10 changes: 5 additions & 5 deletions example/dataloader/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (ec *executionContext) _Customer_address(ctx context.Context, field graphql
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql.
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (ec *executionContext) _Order_items(ctx context.Context, field graphql.Coll
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql.
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -396,7 +396,7 @@ func (ec *executionContext) _Query_torture(ctx context.Context, field graphql.Co
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
8 changes: 4 additions & 4 deletions example/scalars/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field g
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (ec *executionContext) _User_customResolver(ctx context.Context, field grap
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
2 changes: 1 addition & 1 deletion example/selection/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
28 changes: 14 additions & 14 deletions example/starwars/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, fiel
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -459,7 +459,7 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -523,7 +523,7 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -561,7 +561,7 @@ func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -759,7 +759,7 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -814,7 +814,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -858,7 +858,7 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -902,7 +902,7 @@ func (ec *executionContext) _Query_character(ctx context.Context, field graphql.
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -942,7 +942,7 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -985,7 +985,7 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C
return graphql.Defer(func() (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
userErr := ec.Recover(r)
userErr := ec.Recover(ctx, r)
ec.Error(userErr)
ret = graphql.Null
}
Expand Down
Loading

0 comments on commit d157ac3

Please sign in to comment.