You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When using SmartCompositeMessageConverter in other spring-cloud projects (e.g. Spring Cloud Streams), errors are consumed and hidden by the JacksonMapper when using the JsonMessageConverter.
For example, when sending a NestedRuntimeException through StreamBridge on Spring Cloud Streams, it calls SmartCompositeMessageConverter from the SimpleFunctionRegistry.
The converter that is successfully invoked on NestedRruntimeException is the JsonMessageConverter. It calls JacksonMapper toJson on the outgoing payload.
This results in a InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: my.app.kafka.ErrorRecord["exception"]->org.springframework.web.server.ResponseStatusException["mostSpecificCause"])
That makes sense based on the NestedRuntimeException potentially including a self reference.
However, the code for JacksonMapper looks like this:
Because the exception is empty, it silently fails and continues checking the other converters.
This eventually results in a null being returned from SimpleFunctionRegistry.class
(I understand this may be a Spring Cloud Streams issue from this point forward, but I think the log would be extremely helpful to determine that the issue is a serialization issue within JacksonMapper, rather than stemming from the calling library)
This causes the following result in Spring Cloud Streams
// ... StreamBridge send methodMessage<?> resultMessage;
synchronized(this) {
resultMessage = (Message)functionToInvoke.apply(messageToSend); // this becomes "null"
}
...
// This throws a NullPointerException deep in postProcessResult due to resultMessage being nullresultMessage = (Message)this.functionInvocationHelper.postProcessResult(resultMessage, (Object)null);
returnmessageChannel.send(resultMessage);
It therefore makes it very hard to tell what the actual issue was within spring-cloud-function.
Either way, the caller will have to simply assume that null means some issue occurred calling a messageConverter, but in lieu of the exception being available, at least seeing it in the log will allow some information to leak to the developer.
This was discovered when sending a Record<String,Exception>() into Spring Cloud Streams, where only SOME exceptions contain the self reference that causes a failure and others do not. Considering this is somewhat deep in the spring-cloud-function converter workflow, it doesn't feel like a developer issue vs an opportunity to expose some additional information.
Using Spring Cloud Stream as a proxy for any caller, it would be beneficial for a debug/trace log to be available in the JacksonMapper.
Describe the solution you'd like
I'd like a debug log with the given exception in JacksonMapper so that developers are able to determine what caused the error (at least in the JacksonMapper) rather than have to debug through the entire call stack to determine the root problem.
publicbyte[] toJson(Objectvalue) {
byte[] jsonBytes = super.toJson(value);
if (jsonBytes == null) {
try {
jsonBytes = this.mapper.writeValueAsBytes(value);
} catch (Exceptionvar4) {
log.debug("Failed to convert value using " + converter.name() + " with error " + var4.getMessage());
}
}
returnjsonBytes;
}
The text was updated successfully, but these errors were encountered:
I am adding TRACE level logging to ensure that it doesn't pollute the logs. We do provide a stack of converters and we attempt to try them all including the once defined by the user, so logging every failure with anything other then TRACE would pollute teh logs
While we expect failures in individual converters and delegate to others in the stack, this enhancement will allow users to enabel TRACE level logging on failures during 'writeValueAsBytes' in JacksonMapper.
Resolves#1237
Is your feature request related to a problem? Please describe.
When using
SmartCompositeMessageConverter
in other spring-cloud projects (e.g. Spring Cloud Streams), errors are consumed and hidden by theJacksonMapper
when using theJsonMessageConverter
.For example, when sending a
NestedRuntimeException
throughStreamBridge
on Spring Cloud Streams, it callsSmartCompositeMessageConverter
from the SimpleFunctionRegistry.The converter that is successfully invoked on
NestedRruntimeException
is theJsonMessageConverter
. It callsJacksonMapper
toJson on the outgoing payload.This results in a
InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: my.app.kafka.ErrorRecord["exception"]->org.springframework.web.server.ResponseStatusException["mostSpecificCause"])
That makes sense based on the
NestedRuntimeException
potentially including a self reference.However, the code for JacksonMapper looks like this:
Because the exception is empty, it silently fails and continues checking the other converters.
This eventually results in a
null
being returned fromSimpleFunctionRegistry.class
(I understand this may be a Spring Cloud Streams issue from this point forward, but I think the log would be extremely helpful to determine that the issue is a serialization issue within JacksonMapper, rather than stemming from the calling library)
This causes the following result in Spring Cloud Streams
It therefore makes it very hard to tell what the actual issue was within spring-cloud-function.
Either way, the caller will have to simply assume that
null
means some issue occurred calling a messageConverter, but in lieu of the exception being available, at least seeing it in the log will allow some information to leak to the developer.This was discovered when sending a Record<String,Exception>() into Spring Cloud Streams, where only SOME exceptions contain the self reference that causes a failure and others do not. Considering this is somewhat deep in the spring-cloud-function converter workflow, it doesn't feel like a developer issue vs an opportunity to expose some additional information.
Using Spring Cloud Stream as a proxy for any caller, it would be beneficial for a debug/trace log to be available in the JacksonMapper.
Describe the solution you'd like
I'd like a debug log with the given exception in JacksonMapper so that developers are able to determine what caused the error (at least in the JacksonMapper) rather than have to debug through the entire call stack to determine the root problem.
The text was updated successfully, but these errors were encountered: