From d4a2eaf1011b2e7a1d5ec831ef4aab9623e50533 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 13 Nov 2024 16:15:02 +0400 Subject: [PATCH] Throw WorkflowUpdateResultException when an update result was not provided --- src/Client/Update/UpdateHandle.php | 9 ++- .../Client/WorkflowUpdateResultException.php | 55 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/Exception/Client/WorkflowUpdateResultException.php diff --git a/src/Client/Update/UpdateHandle.php b/src/Client/Update/UpdateHandle.php index 4183e531..395aa7db 100644 --- a/src/Client/Update/UpdateHandle.php +++ b/src/Client/Update/UpdateHandle.php @@ -13,6 +13,7 @@ use Temporal\Exception\Client\CanceledException; use Temporal\Exception\Client\TimeoutException; use Temporal\Exception\Client\WorkflowUpdateException; +use Temporal\Exception\Client\WorkflowUpdateResultException; use Temporal\Exception\Client\WorkflowUpdateRPCTimeoutOrCanceledException; use Temporal\Exception\Failure\FailureConverter; use Temporal\Workflow\WorkflowExecution; @@ -127,7 +128,13 @@ private function fetchResult(int|float|null $timeout = null): void // Workflow Uprate accepted $result = $response->getOutcome(); - \assert($result !== null); + $result === null and throw new WorkflowUpdateResultException( + LifecycleStage::tryFrom($response->getStage()), + execution: $this->getExecution(), + workflowType: $this->workflowType ?? '', + updateId: $this->getId(), + updateName: $this->updateName, + ); // Accepted with result if ($result->getSuccess() !== null) { diff --git a/src/Exception/Client/WorkflowUpdateResultException.php b/src/Exception/Client/WorkflowUpdateResultException.php new file mode 100644 index 00000000..ad4ca413 --- /dev/null +++ b/src/Exception/Client/WorkflowUpdateResultException.php @@ -0,0 +1,55 @@ + \sprintf( + "Update `%s` has not yet been accepted or rejected by the Workflow `%s`.", + $updateName, + $workflowType, + ), + default => \sprintf("Update `%s` has no result.", $updateName), + }; + + parent::__construct($message, $execution, $workflowType); + } + + public function getUpdateId(): string + { + return $this->updateId; + } + + public function getUpdateName(): string + { + return $this->updateName; + } + + public function getStage(): LifecycleStage + { + return $this->stage ?? LifecycleStage::StageUnspecified; + } +}