graphql icon indicating copy to clipboard operation
graphql copied to clipboard

executor: adds panic handler

Open chris-ramon opened this issue 7 years ago • 9 comments

Overview

  • graphql: adds PanicHandler type.
  • graphql: adds Params.PanicHandler field.
  • executor: calls PanicHandler when there's a panic while resolving a field.
  • closes: https://github.com/graphql-go/graphql/issues/243
  • built on top of: https://github.com/graphql-go/graphql/pull/252 — thanks a lot @scottjg :+1:

Test plan

  • Unit test.

chris-ramon avatar Oct 22 '17 16:10 chris-ramon

Coverage Status

Coverage increased (+0.009%) to 82.091% when pulling 47767e0f4bbeddee4def9141c0f8909591386f65 on panic-handler into 7731016ba482d3741eea075d23dc6366b932f8f4 on master.

coveralls avatar Oct 22 '17 16:10 coveralls

@chris-ramon thanks for your help with this patch!

i was going over your changes and i have a question... originally my patch would only call the panic handler on an actual panic. it appears with your changes, it gets called when a resolver returns any errors (maybe due to reverting the change here https://github.com/graphql-go/graphql/pull/253/commits/b63c4f02154a8075d775df2a8ccf960485717907#diff-58bccd1b2cfaf06d4d4ac893e4712c88L592 ). was that intentional? if so, is it possible to distinguish between a panic and an error in the panic handler? i think everything gets flattened to a graphql formatted error type so i'm not sure if it's possible.

scottjg avatar Oct 22 '17 18:10 scottjg

Coverage Status

Coverage increased (+0.009%) to 82.234% when pulling 451533e82374cae4032ce83553bb374af94c5a62 on panic-handler into 9b5a661117d443fbf730f165e7424d7ae199856b on master.

coveralls avatar Dec 24 '17 22:12 coveralls

I stuck around on this problem also, I need to know where the stacktrace of the panic in my resolver. is this patch possible to solve that? I used to manually add

defer func() {
	if r := recover(); r != nil {
		log.Println("panic: ", string(debug.Stack()))
		panic(r)
	}
}()

on every resolver. So with this handler I should print with debug.Stack() in the handler? and also why this PR still not merged to master yet, or should I use another version for using this patch?

jekiapp avatar Feb 09 '18 03:02 jekiapp

@chris-ramon Do you have any forecast for the release?

rodrigo-brito avatar Jun 07 '18 19:06 rodrigo-brito

looking forward to get this merged.

niondir avatar Jul 11 '18 14:07 niondir

any updates on this?

phifty avatar Dec 10 '19 10:12 phifty

any updates on this?

jpascal avatar May 08 '21 21:05 jpascal