diff --git a/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowExecutionHandler.java b/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowExecutionHandler.java index 1a78df46f..ebb87604a 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowExecutionHandler.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowExecutionHandler.java @@ -29,6 +29,7 @@ import io.temporal.failure.CanceledFailure; import io.temporal.failure.TemporalFailure; import io.temporal.internal.replay.ReplayWorkflowContext; +import io.temporal.internal.statemachines.UnsupportedContinueAsNewRequest; import io.temporal.internal.worker.WorkflowExecutionException; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.Workflow; @@ -123,6 +124,9 @@ public Optional handleExecuteUpdate( io.temporal.api.common.v1.Header header) { try { return context.handleExecuteUpdate(updateName, input, eventId, new Header(header)); + } catch (UnsupportedContinueAsNewRequest e) { + // Re-throw to fail the workflow task + throw e; } catch (Throwable e) { applyWorkflowFailurePolicyAndRethrow(e); } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateContinueAsNewInHandlerTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateContinueAsNewInHandlerTest.java index 9ab6e3b7e..8757abc64 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateContinueAsNewInHandlerTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateContinueAsNewInHandlerTest.java @@ -20,10 +20,12 @@ package io.temporal.workflow.updateTest; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.*; +import io.temporal.failure.ApplicationFailure; import io.temporal.internal.statemachines.UnsupportedContinueAsNewRequest; import io.temporal.testing.internal.SDKTestOptions; import io.temporal.testing.internal.SDKTestWorkflowRule; @@ -66,7 +68,11 @@ public void continueAsNewInUpdateHandler() { .setUpdateName("update") .setWaitForStage(WorkflowUpdateStage.ACCEPTED) .build()); - assertThrows(WorkflowFailedException.class, () -> stub.getResult(String.class)); + WorkflowFailedException e = + assertThrows(WorkflowFailedException.class, () -> stub.getResult(String.class)); + assertEquals( + "io.temporal.internal.statemachines.UnsupportedContinueAsNewRequest", + ((ApplicationFailure) e.getCause()).getType()); } public static class TestUpdateWorkflowImpl implements WorkflowWithUpdate {