Skip to content

Commit 538a926

Browse files
Only return None for the correct error
Signed-off-by: Elena Kolevska <[email protected]>
1 parent fb7ce53 commit 538a926

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

examples/workflow/monitor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ def send_alert(ctx, message: str):
6363

6464
wf_client = wf.DaprWorkflowClient()
6565
job_id = 'job1'
66-
status = wf_client.get_workflow_state(job_id)
66+
status = None
67+
try:
68+
status = wf_client.get_workflow_state(job_id)
69+
except Exception:
70+
pass
71+
6772
if not status or status.runtime_status.name != 'RUNNING':
6873
# TODO update to use reuse_id_policy
6974
instance_id = wf_client.schedule_new_workflow(

ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from dapr.ext.workflow.workflow_state import WorkflowState
2525
from dapr.ext.workflow.workflow_context import Workflow
2626
from dapr.ext.workflow.util import getAddress
27+
from grpc import RpcError
2728

2829
from dapr.clients import DaprInternalError
2930
from dapr.clients.http.client import DAPR_API_TOKEN_HEADER
@@ -133,9 +134,12 @@ def get_workflow_state(
133134
try:
134135
state = self.__obj.get_orchestration_state(instance_id, fetch_payloads=fetch_payloads)
135136
return WorkflowState(state) if state else None
136-
except Exception as error:
137-
self._logger.error(f'Error fetching workflow state: {error}')
138-
return None
137+
except RpcError as error:
138+
if 'no such instance exists' in error.details():
139+
self._logger.warning(f"Workflow instance not found: {instance_id}")
140+
return None
141+
self._logger.error(f"Unhandled RPC error while fetching workflow state: {error.code()} - {error.details()}")
142+
raise error
139143

140144
def wait_for_workflow_start(
141145
self, instance_id: str, *, fetch_payloads: bool = False, timeout_in_seconds: int = 60

0 commit comments

Comments
 (0)