Workflow Update Method Failure Proper Response

Hello,
I have a workflow update method that is called as a part of an API execution. I want to ask about the proper way to return an exception to the calling service from the update method. I don’t want to fail the workflow here just propagate a proper exception to return a suitable response for the API caller.

Also, there is something that I think I did not understand properly. According to the docs, throwing an ApplicationFailure in the workflow will fail the workflow execution. When I tried it in my update method, the workflow did not fail and no sign of failure was observed on the UI, and I was able to handle the failure as a WorkflowUpdateException. So for that, I thought I’d reach out to know the recommended way of communicating an exception back to the caller of workflow update method.

Hi @Bilal_Fares

TemporalFailure thrown from the update handler won’t fail the workflow, see this comment samples-java/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java at 30c03550420fe596dc0065d2d17e05bc2003dbec · temporalio/samples-java · GitHub

I want to ask about the proper way to return an exception to the calling service from the update method.

Do you need the information to be persisted in the event history? if not I think it is better if you can throw the error from the UpdateValidatorMethod method samples-java/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java at 30c03550420fe596dc0065d2d17e05bc2003dbec · temporalio/samples-java · GitHub.

Let me know if it helps,
Antonio

Hi @antonio.perez
Thanks for ur reply it’s very helpful. I want to know is there a way to propagate my own exceptions in the UpdateValidatorMethod ? In the caller of the UpdateMethod I would like to distinguish between failures and take separate actions upon each.
I am wrapping the exception in an ApplicationFailure object inside the UpdateValidatorMethod but received a WorkflowUpdateException object that cannot be cast into an ApplicationFailure to retrieve the exception type out of it. Is there a way to accomplish that in this case?

Hi @Bilal_Fares

I think e.getCause() should work here

Let me know if it helps,

Antonio

I am using

throw ApplicationFailure.newFailureWithCause(message, exceptionName, exception);

to throw a custom exception in the update method. In the caller service, the exception caught is WorkflowUpdateException. e.getCause() is an ApplicationFailure with type=WorkflowExecutionException. But I would like to get the original exception.

Thanks,

((ApplicationFailure)(e.getCause())).getType() should give you the exception name.

Do you mean to deserialize the original exception?