-
Notifications
You must be signed in to change notification settings - Fork 322
Description
If my handler throws an error, then DataFetcherHandlerMethod
(line 239) returns Mono.error(..)
, and then AnnotatedControllerExceptionResolver
(line 241) tries to convert it to Mono
again, which gives ClassCastException
Lines 239 to 241 in 381c9f3
Object result = exceptionHandler.invoke(env, arguments); | |
Mono<List<GraphQLError>> errorsMono = methodReturnValueAdapter.adapt(result, exception); |
Specifically, in my case I see I threw an error from my handler @GraphQlExceptionHandler fun handle(...): List<GraphQLError> {...}
that ended up here:
doInvoke:129, InvocableHandlerMethodSupport (org.springframework.graphql.data.method)
validateAndInvoke:142, DataFetcherHandlerMethod (org.springframework.graphql.data.method.annotation.support)
invoke:125, DataFetcherHandlerMethod (org.springframework.graphql.data.method.annotation.support)
invokeExceptionHandler:239, AnnotatedControllerExceptionResolver (org.springframework.graphql.data.method.annotation.support)
resolveException:211, AnnotatedControllerExceptionResolver (org.springframework.graphql.data.method.annotation.support)
After that, the Mono.error
with my exception is attempted to be cast to the return type of my handler here:
Lines 444 to 449 in 381c9f3
ReturnValueAdapter forCollection = (result, returnType, ex) -> | |
(result != null) ? | |
Mono.just((result instanceof List) ? | |
(List<GraphQLError>) result : | |
new ArrayList<>((Collection<GraphQLError>) result)) : | |
Mono.empty(); |
Line 446 evaluates to false
because it is instance of Mono
and it tried to cast it to Collection<GraphQLError>
and then fails.
And finally, I don't even get to see my actual error that got thrown in my exception handler in the logs, all I can see are these:
42:57.187 WARN --- [xec-7] a.s.AnnotatedControllerExceptionResolver: Failure while handling exception with *handler signature*
java.lang.ClassCastException...
42:57.189 WARN --- [xec-7] a.s.AnnotatedControllerExceptionResolver: Failure while handling exception with *handler signature*
java.lang.ClassCastException... --- why print the same log AGAIN?
42:57.190 WARN --- [xec-7] s.g.e.ExceptionResolversExceptionHandler: Failure while resolving *resolver signature*
jakarta.validation.ConstraintViolationException... ---- error that got thrown in the code and that I was trying to handle