@@ -40,6 +40,8 @@ import (
4040
4141const (
4242 defaultSignalChannelSize = 100000 // really large buffering size(100K)
43+
44+ panicIllegalAccessCoroutinueState = "getState: illegal access from outside of workflow context"
4345)
4446
4547type (
@@ -461,7 +463,11 @@ func getState(ctx Context) *coroutineState {
461463 if s == nil {
462464 panic ("getState: not workflow context" )
463465 }
464- return s .(* coroutineState )
466+ state := s .(* coroutineState )
467+ if ! state .dispatcher .executing {
468+ panic (panicIllegalAccessCoroutinueState )
469+ }
470+ return state
465471}
466472
467473func (c * channelImpl ) Receive (ctx Context , valuePtr interface {}) (more bool ) {
@@ -1122,7 +1128,14 @@ func (h *queryHandler) execute(input []byte) (result []byte, err error) {
11221128 defer func () {
11231129 if p := recover (); p != nil {
11241130 result = nil
1125- err = fmt .Errorf ("handler for query type %s failed: %v" , h .queryType , p )
1131+ st := getStackTraceRaw ("query handler [panic]:" , 7 , 0 )
1132+ if p == panicIllegalAccessCoroutinueState {
1133+ // query handler code try to access workflow functions outside of workflow context, make error message
1134+ // more descriptive and clear.
1135+ p = "query handler must not use cadence context to do things like cadence.NewChannel(), " +
1136+ "cadence.Go() or to call any workflow blocking functions like Channel.Get() or Future.Get()"
1137+ }
1138+ err = fmt .Errorf ("query handler panic: %v, stack trace: %v" , p , st )
11261139 }
11271140 }()
11281141
0 commit comments