Handling 'workflow not found' error when terminating workflows

Use case:
I want to terminate a workflow if it exists. If it doesn’t, I’d like to ignore the error and proceed without interrupting the flow. I’m looking for a clean or idiomatic way to implement this behavior—any suggestions would be appreciated!

Here’s what I’m currently doing in my application:

handle = client.get_workflow_handle(workflow_id)
desc = await handle.describe()

If the workflow ID doesn’t exist, this throws an exception like:

RPCError: workflow not found for ID: XXX

Is there a specific exception type I can catch for this case? Ideally, I’d like to catch just the “workflow not found” error and ignore it, while allowing other exceptions to propagate.

Thanks in advance team :slight_smile:

You can catch temporalio.service.RPCError
would have notfound status if exec does not exist