ENT-4627 Log transaction context missing exception (#6278)

When a flow is missing its database transaction the _real_ stacktrace
of the exception is missing in the logs. This is due to the normal error
handling path way does not work due the transaction being missing. When
it goes to process the next error event (due to the original transaction
context missing error) it will fail for the same error as it needs the
context to be able to process the error event.

The extra logging should help diagnose future errors.
This commit is contained in:
Dan Newton 2020-05-26 11:32:42 +01:00 committed by GitHub
parent 67298eb780
commit 330a95cb68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,7 +303,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
if(t.isUnrecoverable()) {
errorAndTerminate("Caught unrecoverable error from flow. Forcibly terminating the JVM, this might leave resources open, and most likely will.", t)
}
logger.info("Flow raised an error: ${t.message}. Sending it to flow hospital to be triaged.")
logFlowError(t)
Try.Failure<R>(t)
}
val softLocksId = if (hasSoftLockedStates) logic.runId.uuid else null
@ -342,6 +342,14 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
)
}
private fun logFlowError(throwable: Throwable) {
if (contextTransactionOrNull != null) {
logger.info("Flow raised an error: ${throwable.message}. Sending it to flow hospital to be triaged.")
} else {
logger.error("Flow raised an error: ${throwable.message}. The flow's database transaction is missing.", throwable)
}
}
@Suspendable
override fun <R> subFlow(currentFlow: FlowLogic<*>, subFlow: FlowLogic<R>): R {
subFlow.stateMachine = this