Skip to content

Commit 4bfd85a

Browse files
committed
updated error handling
1 parent 06b7fd7 commit 4bfd85a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcClient.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,15 @@ public void rewindInstance(String instanceId, @Nullable String reason) {
371371
if (reason != null) {
372372
rewindRequestBuilder.setReason(StringValue.of(reason));
373373
}
374-
this.sidecarClient.rewindInstance(rewindRequestBuilder.build());
374+
try {
375+
this.sidecarClient.rewindInstance(rewindRequestBuilder.build());
376+
} catch (StatusRuntimeException e) {
377+
if (e.getStatus().getCode() == Status.Code.FAILED_PRECONDITION) {
378+
throw new IllegalStateException(
379+
"Orchestration instance '" + instanceId + "' is not in a failed state and cannot be rewound.", e);
380+
}
381+
throw e;
382+
}
375383
}
376384

377385
@Override

endtoendtests/src/main/java/com/functions/RewindTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.microsoft.durabletask.azurefunctions.DurableClientContext;
1515
import com.microsoft.durabletask.azurefunctions.DurableClientInput;
1616
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger;
17-
import io.grpc.StatusRuntimeException;
1817

1918
import java.time.Duration;
2019
import java.util.Optional;
@@ -106,7 +105,7 @@ public HttpResponseMessage startRewindNonFailedOrchestration(
106105
try {
107106
client.rewindInstance(instanceId, "Testing rewind on non-failed orchestration");
108107
context.getLogger().info("Rewind request sent for non-failed instance: " + instanceId);
109-
} catch (StatusRuntimeException e) {
108+
} catch (IllegalStateException e) {
110109
context.getLogger().info("Rewind on non-failed instance was rejected (expected): " + e.getMessage());
111110
}
112111

0 commit comments

Comments
 (0)