Activity exceptions / Wrapped Exceptions

Hey!

I am curios about how temporal handle the exception thrown in an activity, specific for the CanceledFailure, currently I am executing heartbeats as part of the activity process and then when a cancelation is requested heartbeat operation throw an exception and in my code I am wrapping the exception as cause of custom exception e.g ServiceException()

So I am wondering if temporal has some internal mechanism to detect the exception and also the causes of the exception.

Base in the functional test that I have executed seems like temporal understand the type of the exception events if its wrapped by another one, because when I cancel the workflow the activity get canceled and it is not retried.

Temporal converts an exception (that is not ApplicationFailure) to an ApplicationFailure and wraps it in an ActivityFailure when delivering it to the workflow.

Got it, my doubt is more about how temporal known that the exception thrown was because a cancellation and not other exception.

As I am currently wrapping all the exception in a own exception I would like to know if I should unwrapped or not.

I would recommend throwing ApplicationFailure directly as it allows attaching details argument.